Solved

executing command line

Posted on 2004-10-02
1
193 Views
Last Modified: 2010-04-15
How do I execute a command line statement in C#?
0
Comment
Question by:arichexe
1 Comment
 
LVL 6

Accepted Solution

by:
der_jth earned 50 total points
ID: 12210516
Use this helper method:

using System.Diagnostics;
...
public static void ExecThroughCmdShell(string command) {

  Process.Start(
    Environment.GetEnvironmentVariable("COMSPEC"),
    " /c " + command
  );
}

The name of the command interpreter is in the COMSPEC env variable (usually something like c:\windows\system32\cmd.exe). You can give cmd.exe a /c param to make it run the rest of the command line and then exit. You can call the method like ExecThroughCmdShell("dir /s /p c:\\windows").
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now