Win32_OperatingSystem 類別的 Win32ShutdownTracker 方法

Win32ShutdownTracker方法在Win32_OperatingSystem中提供Win32Shutdown方法支援的相同關機選項組,但也可讓您指定批註、關機原因或逾時。

語法

uint32 Win32ShutdownTracker(
  [in] uint32 Timeout,
  [in] string Comment,
  [in] uint32 ReasonCode,
  [in] sint32 Flags
);

參數

逾時 [in]

關閉前的時間,以秒為單位。 預設值是 0 (零)。

批註 [in]

要顯示在關機對話方塊中的訊息,該對話方塊也會儲存為事件記錄檔專案中的批註。

ReasonCode [in]

起始關機的原因。

旗標 [in]

要關閉電腦的點陣圖旗標集。 若要強制命令,請將 Force 旗標 (4) 新增至命令值。 使用 Force 搭配遠端電腦上的 [關機] 或 [重新開機] 會立即關閉所有 (,包括 WMI、COM 等) ,或重新開機遠端電腦。 這會導致不確定的傳回值。

0 (0x0)

登出

4 (0x4)

強制登出 (0 + 4)

1 (0x1)

Shutdown

5 (0x5)

強制關機 (1 + 4)

2 (0x2)

重新啟動

6 (0x6)

強制重新開機 (2 + 4)

8 (0x8)

關閉電源

12 (0xC)

強制關閉電源 (8 + 4)

傳回值

傳回零 (0) ,表示成功。 任何其他數字表示發生錯誤。 如需錯誤碼,請參閱 WMI 錯誤常數WbemErrorEnum。 如需一般 HRESULT 值,請參閱 系統錯誤碼

成功 (0)

其他 (1–4294967295)

備註

呼叫進程必須具有 SE_SHUTDOWN_NAME 許可權。

範例

下列 VBScript 程式碼範例說明如何呼叫 Win32ShutdownTracker

Set objArgs = Wscript.Arguments 

intTimeOut = objArgs(0) 'Countdown time (in seconds) before action
strComment = objArgs(1) 'Message to display
intFlags = objArgs(2) 'Set of flags to shutdown the computer:
'0 = Logoff, 4 = Forced Logoff (0+4), 1 = Shutdown, 2 = Reboot, 6 = Forced Reboot (2+4), 8 = Power Off, 12 = Forced Power Off (8+4) - 2 (Reboot) 

strComputer = "." 

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") 

For Each objOperatingSystem in colOperatingSystems 
objOperatingSystem.Win32ShutdownTracker intTimeOut,strComment,0,intFlags 
Next

規格需求

需求
最低支援的用戶端
Windows Vista
最低支援的伺服器
Windows Server 2008
命名空間
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

另請參閱

作業系統類別

Win32_OperatingSystem

Win32Shutdown