閑來無事總要找點事,剛好在複習winfrom,是以對winform如何利用系統程序來開關機來寫個部落格。
1.系統馬上在特定時間後關機。
//系統将在10000秒後關機
decimal nextTime= 10000;
string str = nextTime.ToString();
Process.Start("shutdown.exe", "-s -t " + str);
2.系統馬上關機。
Process.Start("shutdown.exe", "-s");
3.系統重新開機。
Process.Start("shutdown.exe", "-r");
Process.Start("shutdown.exe", "-r -t 10");
4.系統登出。
Process.Start("shutdown.exe", "-l");
-k:并不真正關機,而隻是發出警告資訊給所有使用者。
-r:關機後立即重新啟動。
-h:關機後不重新啟動。
-f:快速關機,重新啟動時跳過fsck。
-n:快速關機,不經過init程式。
-c:取消一個已經運作的shutdown。
-t xxx 設定關閉前的逾時為 xxx 秒。其中預設為30.