For those who prefer a third-party shutdown tool, Sysinternals offers PsShutdown (http://www.sysinternals.com/utilities/psshutdown.html), which provides several additional switch options. You can substitute PsShutdown for shutdown.exe in the GroupedShutdowns script. Depending on what tools you have installed on a PC and how they were installed, you could have more than one version of a tool on your testing PC. If you specify a full path to the tool's location (e.g., C:\resourcekit\shutdown.exe), you can avoid mistakenly running a version of shutdown.exe that has a different syntax. However, if you specify only the filename at a command line or in your scripts and use the shutdown.exe version located first in the path, you might find that you're running a different version of the command than you thought. If your PC has more than one version of shutdown.exe, as my PC did, the shutdown.exe command could fail if you specify switch options that the other version doesn't support. If you aren't sure whether your PC has duplicate versions of a tool, use the Windows 2000 Server Resource Kit Where utility (where.exe) to find all the versions. This sample Where command locates the shutdown.exe file in the PATH variable:
where $path:shutdown.exe
Using GroupedShutdowns
This script assumes that sleep.exe, uptime.exe, and shutdown.exe are in the path on your testing PC. If they aren't in the path, you'll need to specify their location in the script code. To get the GroupedShutdowns script working in your environment, follow these steps: . . .
Dim oFSO, oTS, sClient, oWindows, oLocator, oConnection, oSys
Dim sUser, sPassword
'set remote credentials
sUser = "Administrator"
sPassword = "bhiad,aat!"
'open list of client names
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTS = oFSO.OpenTextFile("C:\clients.txt")
Do Until oTS.AtEndOfStream
'get next client name
sClient = oTS.ReadLine
'get WMI locator
Set oLocator = CreateObject("WbemScripting.SWbemLocator")
'Connect to remote WMI
Set oConnection = oLocator.ConnectServer(sClient, _
"root\cimv2", sUser, sPassword)
'issue shutdown to OS
' 4 = force logoff
' 5 = force shutdown
' 6 = force rebooot
' 12 = force power off
Set oWindows = oConnection.ExecQuery("Select " & _
"Name From Win32_OperatingSystem")
For Each oSys In oWindows
oSys.Win32ShutDown(6) '<---remember to change this to 4,5,6, or 12 and remove this message b4 useing.'
Next
Loop
'close the text file
oTS.Close
WScript.Echo "All done!"
scriptgod December 14, 2005 (Article Rating: