C#實現(xiàn)控制Windows系統(tǒng)關機、重啟和注銷的方法
更新時間:2015年04月14日 09:25:10 作者:令狐不聰
這篇文章主要介紹了C#實現(xiàn)控制Windows系統(tǒng)關機、重啟和注銷的方法,涉及C#調(diào)用windows系統(tǒng)命令實現(xiàn)控制開機、關機等操作的技巧,非常簡單實用,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)控制Windows系統(tǒng)關機、重啟和注銷的方法。分享給大家供大家參考。具體分析如下:
使用.NET和C#.NET,我們可以對當前PC執(zhí)行關機,重啟,注銷操作。
NET Framework中,有一個命名空間System.Diagnostics具有所需的類和方法,從當前PC上運行.NET應用程序來執(zhí)行這些操作。
請使用下面的按鈕來執(zhí)行關機,重啟和注銷。
下面是一個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# VB 實現(xiàn)10進制 16進制之間互相轉(zhuǎn)換
如何將10進制轉(zhuǎn)成16進制,又如何將16進制數(shù)轉(zhuǎn)成10進制,本文將介紹C#和VB實現(xiàn)代碼,需要了解的朋友可以參考下2012-11-11