C # implements methods to control the shutdown, restart, and logoff of Windows systems:

Source: Internet
Author: User

Parameters of the shutdown command:

shutdown.exe-s: Shut down the machine
shutdown.exe-r: Shutdown and restart
shutdown.exe-l: Log off the current user

shutdown.exe-s-t time: Set Shutdown Countdown
shutdown.exe-h: Hibernate
shutdown.exe-t time: Sets the shutdown countdown. The default value is 30 seconds.
shutdown.exe-a: Cancel shutdown
shutdown.exe-f: Forcibly closes the application without warning
shutdown.exe-m \ computer name : Controlling remote computers
shutdown.exe-i: Displays the remote shutdown graphical user interface, but must be the first parameter of shutdown
shutdown.exe-c "message content" : Enter the message contents in the Shutdown dialog box
shutdown.exe-d [u][p]:xx:yy : List reason codes for system shutdown: U is user code, p is a planned shutdown code, XX is a main reason code (positive integer less than 256), YY is a secondary reason code (positive integer less than 65536)

For example, your computer to shut down at 12:00, you can choose "Start → run", enter "at Shutdown-s", so that the 12 point of the computer will appear the "System Shutdown" dialog box, the default has a 30 seconds countdown and prompts you to save the work.
If you want to shut down by a countdown, you can enter "shutdown.exe-s-T 3600", which means auto power off after 60 minutes, and "3600" for 60 Minutes.
One-click Shutdown:
1. First, right-click in the blank space of the desktop and create a new shortcut.
2. In the command line to create the shortcut, enter the following directive:
"Shutdown–s–t 0". (in Windows98 Press this to enter "C:windowsrundll32.exe user,exitwindows". )
3, press the mouse to select "Next", in the Name field of the shortcut enter "one click off" or other favorite name.
4. After that, you will see a shortcut icon called "one button off" on the desktop, right-click on the icon, select "Properties", then go to the "Shortcuts" page, and then in the "Quick Key", select a function key (such as F1-F12). Recommend that you choose a usually not commonly used function keys, and finally press OK to exit.

The Windows system completes the shutdown operation via a program called Shutdown.exe (under Location Windows\System32), and in general the shutdown of the Windows system can be done by the shutdown program Shutdown.exe to implement, call Shutdown.exe when shutting down the machine. It is to prevent the forced shutdown is to cancel the call to Shutdown.exe.

Use C # code to implement methods to control the shutdown, restart, and logoff of Windows systems. NET and C#.net, we can perform shutdown, restart, logout operation on the current PC,
In the. NET Framework, there is a namespace system.diagnostics with the required classes and methods to run. NET applications from the current PC to perform these operations. General use of System.Diagnostics. Process. Start () method to start the Shutdown.exe program.
Below is a WinForm program description that uses buttons to perform shutdown, restart, and logoff.

1         //Shutdown and timer shutdown2         Private voidBtnshutdown_click (Objectsender, EventArgs e)3         {4             if(checkbox1.checked)5             {6                 if(MessageBox.Show ("will you set the scheduled shutdown, confirm the operation? ","Tips", messageboxbuttons.okcancel) = =DialogResult.OK)7                 {8                     decimalDecl = Numericupdown1.value *3600+ Numericupdown2.value * -+Numericupdown3.value;9                     stringstr =Decl. ToString ();TenProcess.Start ("Shutdown.exe","-s-t"+ str);//Timer shutdown One                 } A             } -             Else -             { the                 if(MessageBox.Show ("do you want to confirm the shutdown? ","Tips", messageboxbuttons.okcancel) = =DialogResult.OK) -                 { -Process.Start ("Shutdown.exe","- S");//turn off the machine -                     //Process.Start ("Shutdown.exe", "-s-t xx"); +                 } -             } +         } A         // Restart at         Private voidButrestar_click (Objectsender, EventArgs e) -         { -             if(MessageBox.Show ("do you want to confirm the restart? ","Tips", messageboxbuttons.okcancel) = =DialogResult.OK) -             { -Process.Start ("Shutdown.exe","- R");// Restart -Process.Start ("Shutdown.exe","-r-t Ten"); in             } -         } to         //Logout +         Private voidButlogoff_click (Objectsender, EventArgs e) -         { the             if(MessageBox.Show ("do you want to confirm logout? ","Tips", messageboxbuttons.okcancel) = =DialogResult.OK) *Process.Start ("Shutdown.exe","- L");//Logout $         }Panax Notoginseng  -  the  +  A  the  
View Code

Complete example

C # implements methods to control the shutdown, restart, and logoff of Windows systems:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.