You are on page 1of 2

Sub remoteService(sstrComputer,sstrService,sstrAction)'This accepts a computer n ame, service name, and action to complete on the service.

'Input: sstrComputer = Machine to perform action on. Use "." for local'Input: sstrService = Name of th e service'Input: sstrAction = See options below' "Start" = Start the serv ice' "Stop" = Stop the service' "Restart" = Restart the service' "Pause" = Pause the service' "Resume" = Resume the service' "Automatic" = Set the startup type to Automatic' "Manual" = Set the start up type to Manual' "Disabled" = Set the startup type to Disabled 'To get the status codes:'1. Declare strServiceStatus and blnServiceStatus globally (Ma in part of the script)'2. Call this sub as usual.'3. blnServiceStatus will be set to True if successfull. '4. strServiceStatus will be set to the status of the action On Error Resume Next Set sobjWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & sstrComputer & "\root\cimv2" ) Set scolServiceList = sobjWMIService.ExecQuery("Select * from Win32_Ser vice where Name='" & sstrService &"'") 'Set colServiceList = objWMIService.Ex ecQuery("Select * from Win32_Service") For Each sobjService in scolServiceLi st 'WScript.Echo sobjService.Name sstrAction = UCase(sstrA ction) Select Case sstrAction Case "START" serrReturn = sobjService.StartService() Case "STOP" serrReturn = sobjService.StopService() C ase "RESTART" serrReturn = sobjService.StopService() serrReturn = sobjService.StartService() Case "PAUS E" serrReturn = sobjService.PauseService() Case "RESUME" serrReturn = sobjService.ResumeService() Case "AUTOMATIC" serrReturn = sobjService.C hangeStartMode("Automatic") Case "MANUAL" serrReturn = sobjService.ChangeStartMode("Manual") Case " DISABLED" serrReturn = sobjService.ChangeStartMode("Disabled") End Select 'WScript.Echo serrReturn S elect Case serrReturn Case 0 'Success blnServiceStatus = True strServiceStatus = "Success" Case 1 'Not Supported blnServiceStatus = False strServiceStatus = "Not Supported" Case 2 'Access Denied blnServiceStatus = False strSer viceStatus = "Access Denied" Case 3 'Dependent Service s Running blnServiceStatus = True strServiceStatus = "Dependent Services Running" Case 4 'Invalid Service Control blnServiceStatus = False strServiceStatus = "Invali d Service Control" Case 5 'Service Cannot Accept Control blnServiceStatus = False strServiceStatus = "Service Canno t Accept Control" Case 6 'Service Not Active blnSe rviceStatus = False strServiceStatus = "Service Not Active" Case 7 'Service Request Timeout blnServiceStatus = Fals e strServiceStatus = "Service Request Timeout" Case 8 'Unknown Failure blnServiceStatus = False strS erviceStatus = "Unknown Failure" Case 9 'Path Not Found blnServiceStatus = False strServiceStatus = "Path Not Found " Case 10 'Service Already Running blnServiceStatu s = True strServiceStatus = "Service Already Running" Case 11 'Service Database Locked blnServiceStatus = False strServiceStatus = "Service Database Locked" Case 12 'Service Dependency Deleted blnServiceStatus = True strServiceStatus = "Service Dependency Deleted" Case 13 'Servic e Dependency Failure blnServiceStatus = False strS erviceStatus = "Service Dependency Failure" Case 14 'Service Disa bled blnServiceStatus = True strServiceStatus = "S ervice Disabled" Case 15 'Service Logon Failure bl nServiceStatus = False strServiceStatus = "Service Logon Failure" Case 16 'Service Marked For Deletion blnServiceSt atus = True strServiceStatus = "Service Marked For Deletion"

Case 17 'Service No Thread blnServiceStatus = False strServiceStatus = "Service No Thread" Case 18 'Stat us Circular Dependency blnServiceStatus = False st rServiceStatus = "Circular Dependency" Case 19 'Status Duplicate Name blnServiceStatus = False strServiceStatus = " Duplicate Name" Case 20 'Status Invalid Name blnSe rviceStatus = False strServiceStatus = "Invalid Name" Case 21 'Status Invalid Parameter blnServiceStatus = False strServiceStatus = "Invalid Paramenter" Case 22 'Sta tus Invalid Service Account blnServiceStatus = False strServiceStatus = "Invalid Service Account" Case 23 'Status S ervice Exists blnServiceStatus = True strServiceSt atus = "Service Exists" Case 24 'Service Already Paused blnServiceStatus = True strServiceStatus = "Already Pause d" End Select Next End Sub

You might also like