I want to run commands on the cmd from my C# app.
I tried:
string strCmdText = "ipconfig";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
result:
the cmd window pop but the command didn't do nothing.
why?
For instance, if you wanted to change the drive from C: to D:, you should type: d: … and then press Enter on your keyboard. To change the drive and the directory at the same time, use the cd command, followed by the /d switch.
/C Carries out the command specified by the string and then terminates. You can get all the cmd command line switches by typing cmd /? .
Open Command Prompt in Windows 10Move the mouse pointer to the bottom-left corner of the screen and Right-click, or press Windows key + X. In the power user task menu, select Command Prompt (Admin) (Figure 8). This will open the Command Prompt window (Figure 9).
Use
System.Diagnostics.Process.Start("CMD.exe", "/C ipconfig");
If you want to have cmd still opened use:
System.Diagnostics.Process.Start("CMD.exe", "/K ipconfig");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With