Win32Shutdown method of the Win32_OperatingSystem Class
Applies to: desktop apps only
The Win32Shutdown WMI class method provides the full set of shutdown options supported by Win32 operating systems. These include logoff, shutdown, reboot, and forcing a logoff, shutdown, or reboot. The calling process must have the SE_SHUTDOWN_NAME privilege.
Windows NT 4.0 and Windows Me/98/95: SE_SHUTDOWN_NAME privilege is not required.
This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.
Syntax
uint32 Win32Shutdown( sint32 Flags, sint32 Reserved );
Parameters
- Flags
-
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.
Value Meaning - 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)
- Reserved
-
A means to extend Win32Shutdown. Currently, the Reserved parameter is ignored.
Remarks
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.
Windows Server 2003, Windows XP, Windows 2000, Windows NT 4.0, and Windows Me/98/95: The Win32ShutdownTracker method is not available.
Examples
For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.
For C++ code examples, see WMI C++ Application Examples.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Namespace |
\root\CIMV2 |
|
MOF |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 3/9/2012
$computername= "."
$win32OS = get-wmiobject win32_operatingsystem -computername $computername
$win32OS.psbase.Scope.Options.EnablePrivileges = $true
$win32OS.win32shutdown(8)
- 5/17/2012
- Peddy1st
- 4/15/2012
- I Accept
Dim
testResult AsSingleDim WMIServiceObject, ComputerObject AsObject
'Now get some privileges
WMIServiceObject = GetObject(
"Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")ForEach ComputerObject In WMIServiceObject.InstancesOf("Win32_OperatingSystem")
testResult = ComputerObject.Win32Shutdown(2 + 4, 0)
'reboot'testResult = ComputerObject.Win32Shutdown(0, 0) 'logoff
' testResult = ComputerObject.Win32Shutdown(8 + 4, 0) 'shutdown
If testResult <> 0 Then
MsgBox("Sorry, an error has occurred while trying to perform selected operation")
Else
'Operation selected in statement above if condition would be carried out
EndIf
Next
- 7/3/2008
- Muna
- 9/25/2011
- Thomas Lee
http://mikemstech.blogspot.com/2011/09/powershell-script-to-restart-ip-address.html
- 9/24/2011
- Mike Burr
Could we add a 'Lock Workstation' parameter to this method?
This would provide an alternative to;
> rundll32 user32,LockWorkStation
See Microsoft's lead Windows programmer Raymond Chen's comments on this command:
http://blogs.msdn.com/oldnewthing/archive/2004/01/15/58973.aspx
http://weblogs.asp.net/bdesmond/archive/2003/12/11/43016.aspx
Note that the above command is still part of the MDT Task Sequencer, regardless of these issues:
http://blogs.technet.com/deploymentguys/archive/2008/10/01/back-to-basics-1-locking-the-computer-during-deployment.aspx
Contrary to what Peter mentions I was able to use the method just fine to do a forced shutdown, with Windows 2008 R2 (didn't test with 2008 yet).
Snippet:
Function ShutDown(strComputer)
ShutDown = -1
WScript.Echo "Shutting down: " & strComputer
on error resume next
Set objWMIShutDownService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIShutDownService.ExecQuery("Select * from Win32_OperatingSystem")
If Err <> 0 Then
DisplayErrorInfo
Else
For Each objOperatingSystem in colOperatingSystems
' See: http://msdn.microsoft.com/en-us/library/aa394058(VS.85).aspx
ShutDown = ObjOperatingSystem.Win32Shutdown(1+4,0)
' WScript.Echo ObjOperatingSystem.Name
Next
End If
on error goto 0
End Function
- 11/13/2009
- Paul Weterings
- 11/13/2009
- Paul Weterings
use jawin and WMI, the computer will reboot instead of shutdown
wbemObject = new ISWbemObject();
...
wbemObject.invoke("Win32Shutdown",new Integer(5));
...
but it works fine for win2003.
- 1/5/2009
- peters cheng