大网数据广告活动
Windows 系统接口

Win32ShutdownTracker method of the Win32_OperatingSystem class

· 52CE 我爱测

The Win32ShutdownTracker method provides the same set of shutdown options supported by the Win32Shutdown method in Win32_OperatingSystem, but it also allows you to specify comments, a reason for shutdown, or a timeout.

The Win32ShutdownTracker method provides the same set of shutdown options supported by the Win32Shutdown method in Win32_OperatingSystem, but it also allows you to specify comments, a reason for shutdown, or a timeout.

Syntax

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

Parameters

Timeout [in]

Time, in seconds, before shutdown takes place. The default value is 0 (zero).

Comment [in]

Message to display in the shutdown dialog box that is also stored as a comment in the event log entry.

ReasonCode [in]

Reason for initiating the shutdown.

Flags [in]

Bitmapped set of flags to shut the computer down. To force a command, add the Force flag (4) to the command value. Using Force in conjunction with Shutdown or Reboot on a remote computer immediately shuts down everything (including WMI, COM, and so on), or reboots the remote computer. This results in an indeterminate return value.

0 (0x0)

Log Off

4 (0x4)

Forced Log Off (0 + 4)

1 (0x1)

Shutdown

5 (0x5)

Forced Shutdown (1 + 4)

2 (0x2)

Reboot

6 (0x6)

Forced Reboot (2 + 4)

8 (0x8)

Power Off

12 (0xC)

Forced Power Off (8 + 4)

Return value

Returns zero (0) to indicate success. Any other number indicates an error. For error codes, see WMI Error Constants or WbemErrorEnum. For general HRESULT values, see System Error Codes.

Success (0)

Other (1–4294967295)

Remarks

The calling process must have the SE_SHUTDOWN_NAME privilege.

Examples

The following VBScript code sample describes how to call 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

Requirements

Requirement Value
Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Namespace Root\CIMV2
MOF CIMWin32.mof
DLL CIMWin32.dll

See also

Operating System Classes

Win32_OperatingSystem

Win32Shutdown

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。