Hello,
I am attempting to use VBScript to import a list of servers, stop a service, copy a replacement exe, then restart the service.
I am almost there, however the service is failing to restart once the file is copied.
Any help is appreciated.
On Error Resume Next
Const ForAppending = 8
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\list.txt",1)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name ='SISIDSService'")
For Each objService in colListOfServices
objService.StopService()
Next
'Copy File
objFSO.CopyFile "C:\file.exe" , "C:\Windows\" , OverwriteExisting
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name ='SISIDSService'")
For Each objService in colListOfServices
objService.StartService()
Next
Loop
I am attempting to use VBScript to import a list of servers, stop a service, copy a replacement exe, then restart the service.
I am almost there, however the service is failing to restart once the file is copied.
Any help is appreciated.
On Error Resume Next
Const ForAppending = 8
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\list.txt",1)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name ='SISIDSService'")
For Each objService in colListOfServices
objService.StopService()
Next
'Copy File
objFSO.CopyFile "C:\file.exe" , "C:\Windows\" , OverwriteExisting
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name ='SISIDSService'")
For Each objService in colListOfServices
objService.StartService()
Next
Loop