ASP 本身無權重啟伺服器,需撰寫 ActiveX DLL (COM 元件) 呼叫 Windows API ExitWindowsEx,再由 ASP 透過 Server.CreateObject 調用。
system,類別模組名稱 contral。' 模組程式碼
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
' contral 類別
Public Function reboot(atype As Variant)
Dim t As Long
t = ExitWindowsEx(1, atype)
End Function
system.dll,註冊至伺服器 (regsvr32 system.dll)。<%
Dim atype
atype = Request("atype") ' 0,1,4=關機; 2=重啟
Set sys = Server.CreateObject("system.contral")
sys.reboot(atype)
%>
| atype 值 | 動作 |
|---|---|
| 0 | 登出/關機 |
| 1 | 關機 |
| 2 | 重新啟動 |
| 4 | 強制關機 |