Restart Computers Via VBS Script
Posted on 2006-04-27
Ok, so i found the following script online:
Dim oFSO, oTS, sClient, oWindows, oLocator, oConnection, oSys
Dim sUser, sPassword
'set remote credentials
sUser = "administrator"
sPassword = "password"
'open list of client names
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTS = oFSO.OpenTextFile("C:\Dept Restart\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
'close the text file
WScript.Echo "Machines Restarted!"
Now the clients.txt file that it references, if it only contains one machine name, the script works. But when I try and include more than one machine it give me a "RPC server is unavailable" code: 800706BA, source: SWbemLocator, etc. I'm a networking guy so forgive me, but it would seem to me I have the formatting incorrect on the txt file and so its crapping out. Help please, thank you.