Shutdown or Restart the Computer Using C#
The easiest way to shutdown, restart, or hibernate a computer programmatically using C# is to use the shutdown command-line tool that comes with Windows. This tool has a lot of options, for example /l logs of the user, /s shuts down the computer, /r restarts the computer, and /h hibernates the computer. To get the full list of available options, type help shutdown in the Command Prompt.
To execute shutdown from C# use the follow statement:
|
1 2 |
//the first parameter is the command, and the second is its arguments System.Diagnostics.Process.Start("shutdown", "/s"); |
Download Source Code




Code to Shutdown or Restart the Computer Using C#
ProcessStartInfo startinfo = new ProcessStartInfo(“shutdown.exe”, “-s”);
Process.Start(startinfo);
I hope it works and thanks for the contribution
could you please tell me the proper syntax for shutdown….whenever i try to do this, it shows this error ” The type or namespace name ‘ProcessStartInfo’ could not be found (are you missing a using directive or an assembly reference?) “
it’s working …
thanks
“are you missing a using directive or an assembly reference”
this is your problem exactly as you have to reference System.Diagnostics in order to use ProcessStartInfo class
use the assembly reference as shown below:It works
System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo(“shutdown.exe”, “-s”);
System.Diagnostics.Process.Start(startinfo);