如何用VB.Net調用dos命令shutdown來完成強制關機與重起
代碼如下:
Private Sub DosCommand(ByVal Str_Command As String, ByVal Str_Arguments As String)
Dim Obj_Command As ProcessStartInfo = New ProcessStartInfo()
Dim Pro_Lob As Process = New Process()
Obj_Command.FileName = Str_Command
Obj_Command.RedirectStandardInput = True
Obj_Command.RedirectStandardOutput = True
Obj_Command.RedirectStandardError = True
Obj_Command.CreateNoWindow = True
Obj_Command.UseShellExecute = False
Obj_Command.Arguments = Str_Arguments
Pro_Lob = Process.Start(Obj_Command)
Pro_Lob.Dispose()
End Sub
調用方式:
強制重啟 DosCommand("shutdown", "/f /r")
強制關機 DosCommand("shutdown", "/f /s")
附shutdown命令的使用說明
用法: shutdown [/i | /l | /s | /r | /a | /p | /h | /e] [/f]
[/m [/t]\\computer][/t xxx][/d [p:]xx:yy [/c "comment"]]
沒有參數 顯示説明。這與鍵入 /? 是一樣的
/? 顯示説明。這與不鍵入任何選項是一樣的
/i 顯示圖形化使用者介面(GUI)。
這必須是第一個選項
/l 註銷。這不能與 /m 或 /d 選項一起使用
/s 關閉電腦
/r 關閉並重啟動電腦
/a 放棄系統關閉。
這只能在超時過程中使用
/p 關閉本地電腦,沒有超時或警告。
這只能與 /d 選項一起使用
/h 休眠本地電腦。
這只能與 /f 選項一起使用
/e 將電腦的意外關閉原因記入文檔
/m \\computer 指定目的電腦
/t xxx 設置關閉前的超時為 xxx 秒。
有效範圍是 0-600,默認為 30
/c "comment" 重啟動或關閉的原因的注釋。
最大允許 127 個字元
/f 強制正在運行的應用程式關閉而不事先警告用戶
/d [p:]xx:yy 提供重啟動或關閉的原因
p 表明重啟動或關閉是計畫內的
xx 是主要原因號(小於 256 的正整數)
yy 是次要原因號(小於 65536 的正整數) |