Shutdown or Restart the Computer Using C#

January 8, 2009 | By | 6 Comments

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:

 

Download Source Code

 

Filed in: WinForms | Tags: , ,

Comments (6)

  1. deepak baldia

    Code to Shutdown or Restart the Computer Using C#

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

  2. K TEJ KUMAR

    I hope it works and thanks for the contribution

  3. Fazil

    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?) “

  4. pankaj

    it’s working …

    thanks

  5. Ahmad Moosa

    “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 :)

  6. sukshith

    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);

Leave a Reply

Trackback URL | RSS Feed for This Entry