.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Shutting Down , Restarting or Logging Off Computer using .NET

Posted By:Hefin Dsouza       Posted Date: August 14, 2009    Points: 25    Category: General    URL: http://www.dotnetspark.com  
 

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 Applications As Well As Winforms Application

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

 Subscribe to Articles

     

Further Readings:

Responses
Author: Santosh         Company URL: http://www.dotnetspark.com
Posted Date: September 11, 2009

hi
i am trying with below code to (log off or shutdown or restart) the system.
Process.Start("shutdown.exe","-l")
Process.Start("shutdown.exe","-s")
Process.Start("shutdown.exe","-r")

but it's throwing error like(The system cannot find the file specified).

please send me the solution

with regards,
santosh
Author: Hefin Dsouza         Company URL: http://www.dotnetspark.com
Posted Date: September 12, 2009

Which OS are you Using!
The above code is well tested in Windows XP Service Pack 2 and .NET Framework 2.0/3.5

Regards
Hefin Dsouza
Author: Praveen         Company URL: http://www.dotnetspark.com
Posted Date: September 17, 2009

Hi,
Try like this to shut down system

System.Diagnostics.Process.Start("ShutDown", "/s")

Similarly other you can use below command

/s = shutdown
/r = restart
/t = timed shutdown
Author: Santosh         Company URL: http://www.dotnetspark.com
Posted Date: October 07, 2009

hi

XP OS the above shutdown code is working fine, but i want to run in server 2000.


with Regards
santosh

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend