17

This works:

Process.Start("control", "/name Microsoft.DevicesAndPrinters");

But this doesn't: (It just opens a command prompt.)

ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.Arguments = "control /name Microsoft.DevicesAndPrinters";
Process.Start(info);

Why?

(Yes, I know they're not identical. But the second one "should" work.)

ispiro
  • 26,556
  • 38
  • 136
  • 291

3 Answers3

38

This is because cmd.exe expects a /K switch to execute a process passed as an argument. Try the code below

ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.Arguments = "/K control /name Microsoft.DevicesAndPrinters";
Process.Start(info);

EDIT: Changed to /K above. You can use /C switch if you want cmd.exe to close after it has run the command.

Mofi
  • 46,139
  • 17
  • 80
  • 143
Ravi Y
  • 4,296
  • 2
  • 27
  • 38
7

You need a /c or a /k switch (options for cmd.exe) so that the command is executed. Try:

ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.Arguments = "/c control /name Microsoft.DevicesAndPrinters";
Process.Start(info);
SWeko
  • 30,434
  • 10
  • 71
  • 106
1

Try this one

ProcessStartInfo info = new ProcessStartInfo("control");
info.Arguments = "/name Microsoft.DevicesAndPrinters";
Process.Start(info);
yogi
  • 19,175
  • 13
  • 62
  • 92