Click here to Skip to main content
12,251,352 members (41,772 online)
Click here to Skip to main content
Add your own
alternative version

Stats

258.4K views
5.3K downloads
52 bookmarked
Posted

Run a Command Line Tool as a Windows Application in C#

, 8 Apr 2002
Rate this:
Please Sign up or sign in to vote.
Simple windows application in C# to give command line tools the convenient windows interface

Sample Image

Introduction

It's almost always more convenient to work with a windows GUI other than have to use the DOS command prompt. It's easy to convert a DOS command line tool into a Windows like application in C# by simply adding some Windows Forms tools interacting with some code. 

Here I take the RegenResx.exe as an example. I built a simple windows interface so that I could easily convert old version resx files to be compatible with any version of the .NET framework. This command line tool is very useful when upgrading older version resource files. The tool itself can be found at RegenResx Conversion Tool, or Upgrading from the .NET Framework Beta Versions.  I use the System.Diagnostics namespace and the Process.Start Method. This simple approach could similarly be applied to run other command line tools, DOS commands, and other windows applications. Some examples are also provided in the demo project.

The demo project is a windows form application. A TabControl is put on a Windows form. Each of the three tabs demonstrates a simple situation, either to run a command line tool, a DOS command, or to run another windows application, such as launch Internet Explorer with given address.

Code Sample

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;

    ...

    //Declare and instantiate a new process component.
    System.Diagnostics.Process process1;
    process1= new System.Diagnostics.Process();

    //Do not receive an event when the process exits.
    process1.EnableRaisingEvents = false;


    //The "/C" Tells Windows to Run The Command then Terminate 
    string strCmdLine;
    strCmdLine = "/C regenresx "+textBox1.Text + " " +textBox2.Text;
    System.Diagnostics.Process.Start("CMD.exe",strCmdLine);
    process1.Close();

    ...

Summary

Take the command line tool RegenResx as an example, write the windows interface to convert old version resx files to be compatible with any version of the .NET framework. It's easy and fun to write simple useful application in C# using the powerful .NET Framework.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

shilin
China China
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 1 Pin
Member 767178617-Feb-11 4:17
memberMember 767178617-Feb-11 4:17 
GeneralMinimizing Pin
soloforce11-Jun-09 2:52
membersoloforce11-Jun-09 2:52 
GeneralPrint Word Doc using asp.net using System.Diagnostic.Process Pin
samanthan sadralin17-Feb-05 2:47
membersamanthan sadralin17-Feb-05 2:47 
Questionhow can I get.. Pin
rethore5-Jun-04 0:51
memberrethore5-Jun-04 0:51 
GeneralStart(string, string) is static method Pin
Craig Arnold11-Jun-02 1:33
memberCraig Arnold11-Jun-02 1:33 
GeneralRe: Start(string, string) is static method Pin
Loai16-Nov-02 11:01
memberLoai16-Nov-02 11:01 
GeneralRe: Start(string, string) is static method Pin
J0ker9-Sep-04 5:57
memberJ0ker9-Sep-04 5:57 
GeneralRe: Start(string, string) is static method Pin
chubbysilk21-Sep-04 11:09
memberchubbysilk21-Sep-04 11:09 
GeneralRe: Start(string, string) is static method Pin
cdwilliams26-Sep-06 8:48
membercdwilliams26-Sep-06 8:48 
GeneralRe: Start(string, string) is static method Pin
Lava041-Mar-07 2:23
memberLava041-Mar-07 2:23 
GeneralRe: Start(string, string) is static method Pin
statlidi2-Apr-07 20:29
memberstatlidi2-Apr-07 20:29 
GeneralRe: Start(string, string) is static method Pin
Levona19-May-07 22:04
memberLevona19-May-07 22:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 9 Apr 2002
Article Copyright 2002 by shilin
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid