Click here to Skip to main content
6,595,854 members and growing! (17,792 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate

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

By shilin

Simple windows application in C# to give command line tools the convenient windows interface
C#, Windows, .NET 1.0, Dev
Posted:8 Apr 2002
Views:156,628
Bookmarked:44 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
12 votes for this article.
Popularity: 3.47 Rating: 3.21 out of 5
1 vote, 14.3%
1
1 vote, 14.3%
2
1 vote, 14.3%
3
1 vote, 14.3%
4
3 votes, 42.9%
5

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

About the Author

shilin


Member

Location: China China

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 11 of 11 (Total in Forum: 11) (Refresh)FirstPrevNext
GeneralMinimizing Pinmembersoloforce3:52 11 Jun '09  
GeneralPrint Word Doc using asp.net using System.Diagnostic.Process Pinmembersamanthan sadralin3:47 17 Feb '05  
Generalhow can I get.. Pinmemberrethore1:51 5 Jun '04  
GeneralStart(string, string) is static method PinmemberCraig Arnold2:33 11 Jun '02  
GeneralRe: Start(string, string) is static method PinmemberLoai12:01 16 Nov '02  
GeneralRe: Start(string, string) is static method PinmemberJ0ker6:57 9 Sep '04  
GeneralRe: Start(string, string) is static method Pinmemberchubbysilk12:09 21 Sep '04  
GeneralRe: Start(string, string) is static method Pinmembercdwilliams9:48 26 Sep '06  
GeneralRe: Start(string, string) is static method PinmemberLava043:23 1 Mar '07  
GeneralRe: Start(string, string) is static method Pinmemberstatlidi21:29 2 Apr '07  
GeneralRe: Start(string, string) is static method PinmemberLevona23:04 19 May '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 8 Apr 2002
Editor: Chris Maunder
Copyright 2002 by shilin
Everything else Copyright © CodeProject, 1999-2009
Web09 | Advertise on the Code Project