手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#实现控制Windows系统关机、重启和注销的方法
C#实现控制Windows系统关机、重启和注销的方法
摘要:本文实例讲述了C#实现控制Windows系统关机、重启和注销的方法。分享给大家供大家参考。具体分析如下:使用.NET和C#.NET,我们可以...

本文实例讲述了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#程序设计有所帮助。

【C#实现控制Windows系统关机、重启和注销的方法】相关文章:

用.NET创建Windows服务的方法第1/2页

使用C#获取系统特殊文件夹路径的解决方法

C#实现图片分割方法与代码

C# 设置系统日期格式的方法

c# 获取数据库中所有表名称的方法

.NET(C#):Emit创建异常处理的方法

用C#对ADO.NET数据库完成简单操作的方法

深入理解C#实现快捷键(系统热键)响应的方法

C#利用com操作excel释放进程的解决方法

自定义实现Json字符串向C#对象转变的方法

精品推荐
分类导航