Shutdown method of the Win32_OperatingSystem class
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 |
|
DLL |
|