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