I am trying to use the following script to stop and disable a services that is not needed. (not the service in this script) My question is why to I get error:0x80041021, Code: 80041021 for line 13 when it runs. It will work through the list and stop the service but then kicks out the error. Also is there a way to add the disbale into this code (line 23 - commented out) I am not a programmer but I need to accomplish this task. Any and all help will be appreciated.
Thank you,
Maria
strCurrentDir = GetCurrentDirectory() &"\"
strServerList = strCurrentDir & "AGC_Servers.xls"
' Open spreadsheet for Servers
Set oXL = WScript.CreateObject("EXCEL.application")
oXL.Visible = True
oXL.workbooks.open strServerList
oXL.sheets("Sheet1").Activate
introw = 2
Do
strComputer = oXL.Cells(intRow, 2).Value
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='Schedule'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For Each objService in colServiceList
If objService.Name = "Schedule" & objService.State = 4 Then
objService.StopService()
End If
' If objService.Name = "Schedule" & objService.StartType = "Auto" Then
' objService.ChangeStartType("Disabled")
' End If
Next
Set colServiceList2 = objWMIService.ExecQuery ("Select * from Win32_Service where Name='Schedule'")
'BackupExecAgentAccelerator
For Each objService in colServiceList2
errReturn = objService.StopService()
Wscript.Sleep 5000
If errReturn = 0 then
oXL.Cells(intRow,3).Value = "service is now stopped"
ElseIf errReturn = 5 then
oXL.Cells(intRow,3).Value = "Service was already stopped"
ElseIf errReturn <> 0 or errReturn <> 5 Then
oXL.Cells(intRow,3).Value = "Error stopping the service"
End If
Next
intRow = intRow + 1
Loop Until strComputer = ""
oXL.activeworkbook.save
oXL.workbooks.close
oXL.application.quit()
Function GetCurrentDirectory()
GetCurrentDirectory = Left(WScript.ScriptFullName,InstrRev(WScript.ScriptFullName,"\") -1)
End Function
Thank you,
Maria
strCurrentDir = GetCurrentDirectory() &"\"
strServerList = strCurrentDir & "AGC_Servers.xls"
' Open spreadsheet for Servers
Set oXL = WScript.CreateObject("EXCEL.application")
oXL.Visible = True
oXL.workbooks.open strServerList
oXL.sheets("Sheet1").Activate
introw = 2
Do
strComputer = oXL.Cells(intRow, 2).Value
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='Schedule'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For Each objService in colServiceList
If objService.Name = "Schedule" & objService.State = 4 Then
objService.StopService()
End If
' If objService.Name = "Schedule" & objService.StartType = "Auto" Then
' objService.ChangeStartType("Disabled")
' End If
Next
Set colServiceList2 = objWMIService.ExecQuery ("Select * from Win32_Service where Name='Schedule'")
'BackupExecAgentAccelerator
For Each objService in colServiceList2
errReturn = objService.StopService()
Wscript.Sleep 5000
If errReturn = 0 then
oXL.Cells(intRow,3).Value = "service is now stopped"
ElseIf errReturn = 5 then
oXL.Cells(intRow,3).Value = "Service was already stopped"
ElseIf errReturn <> 0 or errReturn <> 5 Then
oXL.Cells(intRow,3).Value = "Error stopping the service"
End If
Next
intRow = intRow + 1
Loop Until strComputer = ""
oXL.activeworkbook.save
oXL.workbooks.close
oXL.application.quit()
Function GetCurrentDirectory()
GetCurrentDirectory = Left(WScript.ScriptFullName,InstrRev(WScript.ScriptFullName,"\") -1)
End Function