Shutting Down , Restarting or Logging Off Computer in a Simple Way

The following codes will be helpfull for Shuting Down , Restarting or Logging Off Current System from a .Net Application.

Shuting Down
C# - Remember to add Using System.Diagnostics
Then in any Event Handler Enter


Process.Start("shutdown.exe","-s"); // By Default the Shutdown will take place after 30 Seconds if you want to change the Delay try this one
//Process.Start("shutdown.exe","-s -t xx"); //Replace xx with Seconds example 10,20 etc


VB.Net - Remember to add Imports System.Diagnostics
Then in any Event Handler Enter

Process.Start("shutdown.exe","-s")' By Default the Shutdown will take place after 30 Seconds if you want to change the Delay try this one
'Process.Start("shutdown.exe","-s -t xx")'Replace xx with Seconds example 10,20 etc

Restarting Computer
C# - Remember to add Using System.Diagnostics
Then in any Event Handler Enter

Process.Start("shutdown.exe","-r"); // By Default the Restart will take place after 30 Seconds if you want to change the Delay try this one
//Process.Start("shutdown.exe","-r -t xx"); //Replace xx with Seconds example 10,20 etc


VB.Net - Remember to add Imports System.Diagnostics
Then in any Event Handler Enter

Process.Start("shutdown.exe","-r")' By Default the Restart will take place after 30 Seconds if you want to change the Delay try this one
'Process.Start("shutdown.exe","-r -t xx")'Replace xx with Seconds example 10,20 etc

Logging Off
C# - Remember to add Using System.Diagnostics
Then in any Event Handler Enter

Process.Start("shutdown.exe","-l"); //This Code Will Directly Log Off the System Without warnings


VB.Net - Remember to add Imports System.Diagnostics
Then in any Event Handler Enter

Process.Start("shutdown.exe","-l")'This Code Will Directly Log Off the System Without warnings


This Code Can Be Used in Both Console As Well As Windows Application

If you face any problems simply post a response.
Regards
Hefin Dsouza


Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: