Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reboot Remote Computer via WMI - NOT WORKING FOR MULTIPLE COMPUTERS

5 views
Skip to first unread message

Megan Kielman

unread,
Sep 1, 2004, 6:05:09 PM9/1/04
to
Hi all, I obtained the below script from the MS Script Center, I included
this in a vbscript that actually pulls a list of computers to reboot from a
spreadsheet. I started out with approximately 100 computers in the
spreadsheet, the script would run w/o error but it wouldn't reboot the
computers. However, when I narrowed down the spreadsheet to like 10
computers, it would work just fine. What gives?!

--------------piece from MS------------------------------------

strComputer = "atl-dc-01"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer &
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next

------------------------------------------------------------------

My Code, which incorporates the above code:

'Get setup to read the directory
Set rootDSE = GetObject("LDAP://wawwcidc10/RootDSE") 'bind directly to
server
Server = rootDSE.Get("dnsHostName")
Set oConnection = CreateObject("ADODB.Connection")
Set oRecordSet = CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oRecordSet.ActiveConnection = oConnection

'Read an Excel spreadsheet.
'Create the XLS object and get ready to read
Set XLObj = CreateObject("Excel.Application")
Call XLObj.Workbooks.Open("d:\scripts\rothtest.xls", 0) 'Name of the
spreadsheet goes here
If Err.Number <> 0 Then
MsgBox "Unable to read spreadsheet"
WScript.Quit
End If
XLObj.Sheets("Sheet1").Activate ' this is the sheet name
Row = 2 'goto Row 2, bypass header

'Read each cell of the spreadsheet until it's blank
Do Until XLObj.Range("A:A").Cells(Row).Text = "" 'loop until end of
worksheet
CompName = RTrim(XLObj.Range("A:A").Cells(Row).Text) 'pull the groupname
from the speadsheet.
UserName = RTrim(XLObj.Range("B:B").Cells(Row).Text) 'pull the username
from the speadsheet.

'Now get the group name
Set oRecordSet = oConnection.Execute("<LDAP://" & Server & ">;" & _
"(name=" & CompName & ");name,CN,distinguishedName;subtree")
If Not oRecordSet.EOF Then 'User found continue processing

'Get the computers based on the distinguished name
Set objComp = GetObject("LDAP://" & Server & "/" &
oRecordSet.Fields("distinguishedName").Value)

'Restart Computer

Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,(Shutdown)}!\\" & CompName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next

End if
Row = Row + 1
Loop

'Cleanup
Set oDest = Nothing
'Set oUsers = Nothing
XLObj.ActiveWorkbook.Save
XLObj.ActiveWorkbook.Close
Set UserFile = Nothing
wscript.quit


David H. Lipman

unread,
Sep 1, 2004, 6:44:26 PM9/1/04
to
Why reinvent the wheel ?

Why not just call the Resource Kit utility SHUTDOWN.EXE from the script ?

Dave

"Megan Kielman" <megan.kielman@(removethis)weyerhaeuser.com> wrote in message
news:OShJA$GkEH...@TK2MSFTNGP12.phx.gbl...

Megan Kielman

unread,
Sep 1, 2004, 7:33:19 PM9/1/04
to
How would I do that?

But I want to know why this code isn't working!!!

"David H. Lipman" <DLipman~nospam~@Verizon.Net> wrote in message
news:uz15tUHk...@TK2MSFTNGP12.phx.gbl...

Yevgen Lazaryev

unread,
Sep 1, 2004, 7:43:50 PM9/1/04
to

"Megan Kielman" <megan.kielman@(removethis)weyerhaeuser.com> a écrit dans le
message de news:%23NybRwH...@TK2MSFTNGP12.phx.gbl...

| How would I do that?
|
| But I want to know why this code isn't working!!!

....probably your script is running too fast for computers to respond ...
Try to add some WScript.Sleep(3000) or some bigger delay and look if it
works ...


Megan Kielman

unread,
Sep 13, 2004, 11:11:02 AM9/13/04
to
Where should I add WScript.Sleep? at the end of the script so that there is
a pause before it runs it for each computer?


"Yevgen Lazaryev" <elaz...@yahoo.com> wrote in message
news:uGRKN2H...@TK2MSFTNGP09.phx.gbl...

Yevgen Lazaryev

unread,
Sep 13, 2004, 7:57:13 PM9/13/04
to
...you add it not in the end of the script but in the end of the loop
....Just before the line Loop in your script ...

"Megan Kielman" <megan.kielman@(removethis)weyerhaeuser.com> a écrit dans le

message de news:uckkkPam...@TK2MSFTNGP10.phx.gbl...

0 new messages