I want to create a process which uses shutdown.exe to shut down the computer after a given time.
Here is my code:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "shutdown.exe";
startInfo.Arguments = "–s –f –t " + seconds;
Process.Start(startInfo);
Where seconds is an int local variable, the user decides.
When i run my code nothing happens. But when i manually go in cmd prompt and type:
shutdown.exe - s -f -t 999
then Windows will make a popup and tell me that the system will shutdown in 16 mins.
The reason i think it's because of the multiple arguments, is that my method to abort the ongoing system shutdown works(where i created the systemshutdown manually from cmd prompt). This is almost the same, except at startInfo.Argument:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "shutdown.exe";
startInfo.Arguments = "-a";
Process.Start(startInfo);