Mohanad's "Blog" 🤓👋

Execute cmd commands using C#

Hello again , 
If you want to execute cmd commands from c# you can use this method :

private void ExecuteCommand(string Command)
{
    ProcessStartInfo ProcessInfo;
    Process Process;

    ProcessInfo = new ProcessStartInfo("cmd.exe", "/C " + Command);
    ProcessInfo.CreateNoWindow = false;
    ProcessInfo.UseShellExecute = false;
    Process = Process.Start(ProcessInfo);
    Process.WaitForExit();

    Process.Close();
}

If you like to execute multi commands in the same process you can just seperate each one with "&"

like this :


ExecuteCommand("cd & myApp.exe");

where "cd" is the first command and "myApp.exe" is the second one.

Enjoy it..