Create Service - Set Recovery Options

L

Lando

I have a script below to create a service for launching IE in kiosk mode on
a PC. I want to set the recover options to restart the service should it
fail. Does anyone know what I need to add to my script below to set the 1st,
2nd and Subsequent failures to "Restart Service"?

Thanks in advance for your help.
Lando

**********************************
sComputer = "."
sStartMode = "Automatic"
StartName = "LocalSystem"
StartPassword = ""
sName = "IECheck"
sDisplayName = "IECHECK Restart IE When Closed"
sPathName = "c:\progra~1\intern~1\iexplore.exe -k"
bDeskInteract = True
iErrorControl = 1

Set oInstance = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sComputer & "/root/cimv2:Win32_Service")

Set oMethod = oInstance.Methods_("Create")
Set oInParam = oMethod.inParameters.SpawnInstance_()
oInParam.Name = sName
oInParam.DisplayName = sDisplayName
oInParam.PathName = sPathName
'--oInParam.ServiceType = iServiceType
'--oInParam.ErrorControl = iErrorControl
oInParam.StartMode = sStartMode
oInParam.DesktopInteract = bDeskInteract
'--oInParam.StartName = sStartName
'--oInParam.StartPassword = sStartPassword
'--oInParam.LoadOrderGroup = sLoadOrderGroup
'--oInParam.LoadOrderGroupDependencies = aLoadOrderGroupDependencies
'--oInParam.ServiceDependencies = aServiceDependencies

Set oOutParam = oInstance.ExecMethod_("Create", oInParam)

If oOutParam.ReturnValue = 0 Then
WScript.Echo "Service " & sName & " created successfully"
Else
WScript.Echo "Create method for service " & sName & " failed"
Select Case oOutParam.ReturnValue
Case 1 WScript.Echo "Not Supported"
Case 2 WScript.Echo "Access Denied"
Case 3 WScript.Echo "Dependent Services Running"
Case 4 WScript.Echo "Invalid Service Control"
Case 5 WScript.Echo "Service Cannot Accept Control"
Case 6 WScript.Echo "Service Not Active"
Case 7 WScript.Echo "Service Request Timeout"
Case 8 WScript.Echo "Unknown Failure"
Case 9 WScript.Echo "Path Not Found"
Case 10 WScript.Echo "Service Already Running"
Case 11 WScript.Echo "Service Database Locked"
Case 12 WScript.Echo "Service Dependency Deleted"
Case 13 WScript.Echo "Service Dependency Failure"
Case 14 WScript.Echo "Service Disabled"
Case 15 WScript.Echo "Service Logon Failure"
Case 16 WScript.Echo "Service Marked For Deletion"
Case 17 WScript.Echo "Service No Thread"
Case 18 WScript.Echo "Status Circular Dependency"
Case 19 WScript.Echo "Status Duplicate Name"
Case 20 WScript.Echo "Status Invalid Name"
Case 21 WScript.Echo "Status Invalid Parameter"
Case 22 WScript.Echo "Status Invalid Service Account"
Case 23 WScript.Echo "Status Service Exists"
Case 24 WScript.Echo "Service Paused"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dump of perfection Test 1

Top