Discussion Locked

WMI Reboot Script

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm trying to develop a script that will read from a text file the servers I would like rebooted.

Can some Help?

Thanks

2 replies

by harun

From ColdHonedSteel
http://www.codecomments.com/archive300-2004-5-174101.html

Call sShutdown "ForceShutdown "

Sub sShutdown(strType)
Const wbemFlagForwardOnly = &H20, wbemFlagReturnImmediately = &H10
Const Logoff = 0, Shutdown = 1, Reboot = 2
Const ForceLogoff = 4, ForceShutdown = 5, ForceReboot = 6
Const PowerOff = 8, ForcePowerOff = 12

Dim colOperatingSystems, objOperatingSystem, intShutdownType

strType = LCase(strType)
Select Case strType
Case "logoff"
intShutdownType = 0
Case "shutdown"
intShutdownType = 1
Case "reboot"
intShutdownType = 2
Case "forcelogoff"
intShutdownType = 4
Case "forceshutdown"
intShutdownType = 5
Case "forcereboot"
intShutdownType = 6
Case "poweroff"
intShutdownType = 8
Case "forcepoweroff"
intShutdownType = 12
Case Else MsgBox "Please select one of the 8 available shutdown types!"
End Select

Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(intShutdownType)
Next
End Sub

============================= Begin Documentation =========================
' ***** Shutdown Description *****
' Value Description
'
' 0 Logoff.
' Logs the user off the computer. Logging off stops all processes
' associated with the security context of the process that called
' the exit function, logs the current user off the system, and
' displays the logon dialog box.
'
' 1 Shutdown.
' Shuts down the computer to a point where it is safe to turn off
' the power. (All file buffers are flushed to disk, and all
' running processes are stopped.) Users see the message, It is
' now safe to turn off your computer.
' During shutdown the system sends a message to each running
' application. The applications perform any cleanup while
' processing the message and return True to indicate that they
' can be terminated.
'
' 2 Reboot.
' Shuts down and then restarts the computer.
'
' 4 Forced logoff.
' Logs the user off the computer immediately and does not
' notify applications that the logon session is ending. This can
' result in a loss of data.
'
' 5 Forced shutdown.
' Shuts down the computer to a point where it is safe to
' turn off the power. (All file buffers are flushed to disk, and
' all running processes are stopped.) Users see the message, It
' is now safe to turn off your computer.
' When the forced shutdown approach is used, all services,
' including WMI, are shut down immediately. Because of this, you
' will not be able to receive a return value if you are running
' the script against a remote computer.
'
' 6 Forced reboot.
' Shuts down and then restarts the computer. When the forced
' reboot approach is used, all services, including WMI, are shut
' down immediately. Because of this, you will not be able to
' receive a return value if you are running the script against a
' remote computer.
'
' 8 Power off.
' Shuts down the computer and turns off the power (if supported
' by the computer in question).
'
' 12 Forced power off.
' Shuts down the computer and turns off the power (if
' supported by the computer in question). When the forced power
' off approach is used, all services, including WMI, are shut
' down immediately. Because of this, you will not be able to
' receive a return value if you are running the script against a
' remote computer.
'
'
'============================= End Documentation ===========================

This discussion is closed to new replies.