Abdulsalam Elsharif
Abdulsalam Elsharif

Reputation: 5121

Execute CMD shutdown command in WPF

I want to run a command in my application that will shutdown another computer in LAN, I used:

string CmdText = "shutdown -m \\192.168.1.5 -r -c \"Will shutdown\" -t 10";
Process.Start("cmd", CmdText);

but it dose not work :( the cmd windows appeared but nothing happen, the computer dose not shutdown.

When I try (for example):

string CmdText = "dir";
Process.Start("cmd", CmdText);

It works.

What it's the problem ?

Upvotes: 0

Views: 1454

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 157136

Just run the process directly, without using cmd:

Process.Start("shutdown", "-m \\\\192.168.1.5 -r -c \"Will shutdown\" -t 10");

Don't forget to escape the \ of the server name. Also, start the process as administrator:

ProcessStartInfo startInfo = new ProcessStartInfo("shutdown", "-m \\\\192.168.1.5 -r -c \"Will shutdown\" -t 10");
startInfo.Verb = "runas";

Process.Start(startInfo);

Upvotes: 4

Related Questions