Greetings,
I've migrated a VBS script from 2008 to 2012. The script shutdowns or starts Microsoft services. On Server 2008, I have no issues, but on 2012, I get the error "\VBS\MS_Services.vbs(192, 2) Microsoft VBScript runtime error: Object required: 'GetServiceObject(...)' "
The script's logic stops services on several servers.
It does stop the server on the first server on the list however yields the error "GetServiceObject" when jumping to the next server on the list.
I've seen in this forum the same type of issues when migrating from 2008 to 2012, but have not seen a resolution yet. I'm hoping this post will shed some light.
Main function:
Case "STOP"
strMailBody = strMailBody & "Stop Services" & vbCrLf & vbCrLf
For intServiceNumber = 1 To 10
aServiceResponses(intServiceNumber) = StopSVC(aServices(intServiceNumber))
Next
' ************ Function StopSVC
Function StopSVC(aService)
strServerName = aService(SERVERNAME)
strService = aService(SERVICENAME)
strServiceName = aService(SHORTNAME)
intSuccess = 0 ' flag to indicate the service stopped successfully
Set objService = GetServiceObject(aService, True) ' Get Service Object
objService.StopService() ' send the service the command, then check its state
StopSVC = WaitForServiceState(aService, STOPWAITDELAY, "Stopped")
End Function
' ************ Function GetServiceObject
Function GetServiceObject(aService, boolShowCommandLineOutput)
strServerName = aService(SERVERNAME)
strService = aService(SERVICENAME)
strServiceName = aService(SHORTNAME)
' Output some niceness to the screen when running from a command prompt
If boolShowCommandLineOutput Then WScript.Echo strServerName & ": " & strServiceName
' Get services collection through WMI
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServerName & "\root\cimv2")
Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service where " & "DisplayName = '" & strService & "'")
' Get Service object (there should only ever be 1 object in the collection)
For each objService in colServices
Set GetServiceObject = objService
Next
End Function