Saturday, September 4th, 2010

Shut Down, Restart and Log Off PC using .NET, C#

Using .NET and C#.NET, We can perform Shut Down, Restart and Log off operation on current PC.
In .NET Framework we have a namespace Using System.Diagnostics which has the required class and methods to perform these operations from a .NET application running on a current PC.

Please Use the below buttons to perform Shutdown, Restart and Logoff on Current PC.

diagnostics.aspx.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//SHUT DOWN
        protected void btnShutDown_Click(object sender, EventArgs e)
        {            
            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
        }
 
//RESTART
        protected void btnRestart_Click(object sender, EventArgs e)
        {
            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 10"); //Replace xx with Seconds example 10,20 etc
        }
 
// LOG OFF
        protected void btnLogOff_Click(object sender, EventArgs e)
        {
            Process.Start("shutdown.exe", "-l"); //This Code Will Directly Log Off the System Without warnings
        }
Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Tags: , , , , ,

Readers Comments (0)




Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


Latest Additions

Popular User Submitted Links

1


Hosted & Optimized JS Libraries – Cached Commons

1


Multi-File Uploader & Resizer – Agile Uploader

1


Open source online notebook-to-do-list manager

1


3 tier app design in silverlight using azure & RIA services

1


Polymaps – A JS Library For Image & Vector-Tiled Maps

eXTReMe Tracker