Export (0) Print
Expand All

Shutdown method of the Win32_OperatingSystem class

The ShutdownWMI 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.

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

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

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

 

 

Show:
© 2014 Microsoft