Shutdown or Restart the Computer Using C#

Amgad | January 8, 2009 | 1 Comments | 3589 Visits

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:

//the first parameter is the command, and the second is its arguments
System.Diagnostics.Process.Start("shutdown", "/s");

 

Download Source Code

Related posts:

Filed Under: WinForms

Comments

  1. deepak baldia says:

    Code to Shutdown or Restart the Computer Using C#

    ProcessStartInfo startinfo = new ProcessStartInfo(“shutdown.exe”, “-s”);
    Process.Start(startinfo);

Leave a Reply