--------------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
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...
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...
....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 ...
"Yevgen Lazaryev" <elaz...@yahoo.com> wrote in message
news:uGRKN2H...@TK2MSFTNGP09.phx.gbl...
"Megan Kielman" <megan.kielman@(removethis)weyerhaeuser.com> a écrit dans le
message de news:uckkkPam...@TK2MSFTNGP10.phx.gbl...