Solved

executing command line

Posted on 2004-10-02
1
181 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

709 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

13 Experts available now in Live!

Get 1:1 Help Now