本文實例講述了C#實現控制Windows系統關機、重啟和注銷的方法。分享給大家供大家參考。具體分析如下:
使用.NET和C#.NET,我們可以對當前PC執行關機,重啟,注銷操作。
NET Framework中,有一個命名空間System.Diagnostics具有所需的類和方法,從當前PC上運行.NET應用程序來執行這些操作。
請使用下面的按鈕來執行關機,重啟和注銷。
下面是一個winform程序
//SHUT DOWNprotected 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}//RESTARTprotected 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 OFFprotected void btnLogOff_Click(object sender, EventArgs e){ Process.Start("shutdown.exe", "-l"); //This Code Will Directly Log Off the System Without warnings}
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答