本文实例讲述了c#实现控制windows系统关机、重启和注销的方法。分享给大家供大家参考。具体分析如下:
使用.net和c#.net,我们可以对当前pc执行关机,重启,注销操作。
net framework中,有一个命名空间system.diagnostics具有所需的类和方法,从当前pc上运行.net应用程序来执行这些操作。
请使用下面的按钮来执行关机,重启和注销。
下面是一个winform程序
//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 }
希望本文所述对大家的c#程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论