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

Shutdown method of the Win32_OperatingSystem class

· 52CE 我爱测

The Shutdown&\#8194;WMI class method unloads programs and DLLs until it is safe to turn off the computer.

The Shutdown WMI class method unloads programs and DLLs until it is safe to turn off the computer.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 Shutdown();

Parameters

This method has no parameters.

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

Computers occasionally need to be removed from the network, perhaps for scheduled maintenance, because the computer is not functioning correctly, or to complete a configuration process. For example, if a DHCP server is handing out erroneous IP addresses, you might want to shut the computer down until a service technician can be dispatched to fix the problem. If you suspect that a security breach has occurred, you might need to shut down certain servers to ensure that they cannot be accessed until the security issue has been resolved. Some configuration operations (such as changing a computer name) require you to restart the computer before the change takes effect.

This method immediately shuts the computer down, if possible. The system stops all running processes, flushes all file buffers to the disk, and then powers down the system. The calling process must have the SE_SHUTDOWN_NAME privilege, as described in the following example.

Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")

For more information on setting a privilege, see Executing Privileged Operations and Executing Privileged Operations Using VBScript. For additional shutdown options, such as a logoff or a forced shutdown, see the Win32Shutdown method.

Examples

The following VBScript code shuts the local computer down.

Note:
You must have the Shutdown privilege to successfully invoke the Shutdown method.

Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")

for each OpSys in OpSysSet
 OpSys.Shutdown()
next

The following Perl code shuts the local computer down.

Note:
You must have the Shutdown privilege to successfully invoke the Shutdown method.

use strict;
use Win32::OLE;

my $OpSysSet;

eval { $OpSysSet = Win32::OLE->GetObject("winmgmts:{(Shutdown)}//./root/cimv2")->
      ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Primary=true"); };

if(!$@ && defined $OpSysSet)
{
 close (STDERR);
 foreach my $OpSys (in $OpSysSet)
 {
  my $RetVal = $OpSys->Shutdown();
  if (!defined $RetVal || $RetVal != 0)
  { 
   print Win32::OLE->LastError, "\n";
  }
 }
}
else
{
 print STDERR Win32::OLE->LastError, "\n";
}

The following VBScript code shuts the specified remote computer down. Fill in REMOTE_SYSTEM_NAME with the name of the remote system to shutdown.

Note:
You must have the RemoteShutdown privilege to successfully invoke the Shutdown method.

Set OpSysSet = GetObject("winmgmts:{(Debug,RemoteShutdown)}//REMOTE_SYSTEM_NAME/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")

for each OpSys in OpSysSet
 OpSys.Shutdown()
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

WMI Tasks: Desktop Management

Executing Privileged Operations Using VBScript

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)

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

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