源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C#实现控制Windows系统关机、重启和注销的方法

  • 时间:2021-06-11 01:04 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#实现控制Windows系统关机、重启和注销的方法
本文实例讲述了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#程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部