Basic skills (12) -------- C # program logout, restart, shutdown, and lock the computer

Source: Internet
Author: User
I:

Ii. Source Code
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. windows; using system. windows. controls; using system. windows. data; using system. windows. documents; using system. windows. input; using system. windows. media; using system. windows. media. imaging; using system. windows. navigation; using system. windows. shapes; using system. diagnostics; using system. runtime. interopservices; one-click lock for namespace shutdown {// <summary> // mainwindow. interaction logic of XAML // </Summary> Public partial class mainwindow: window {public mainwindow () {initializecomponent () ;}// shut down private void btnshutdown_click (Object sender, routedeventargs e) {// PROCESS p = new process (); // instantiate an independent process // P. startinfo. filename = "shutdown"; // P. startinfo. arguments = "-s-t 0"; // P. start (); // start // It is equivalent to the above four processes. start ("shutdown", "-s-t 0");} private void btnreset_click (Object sender, routedeventargs e) {// restart process. start ("shutdown", "-r-t 0");} private void btnunlogin_click (Object sender, routedeventargs e) {// cancel process. start ("shutdown", "-l"); // C # Write shutdown, restart, and deregister programs, simple code mainly uses the process class for operations} [dllimport ("user32.dll")] public static extern void lockworkstation (); // one-click private void btnclose_click (Object sender, routedeventargs E) {lockworkstation () ;}// open the CMD window private void btn1__click (Object sender, routedeventargs e) {process. start ("cmd ");}}}

 

Iii. Conclusion

Of course, I am not doing this to make it easier for everyone to shut down, restart, unregister and lock, and open the CMD window. Microsoft provides you with convenient shortcut keys, such as win + R, win + L and so on. Don't talk about it any more. It's just for entertaining code.

Basic skills (12) -------- C # program logout, restart, shutdown, and lock the computer

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.