1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
Option Explicit
ManageService
Private Function ManageService()
'local Constante
Const intSleep = 15000
Const strComputer = "."
Const strServiceName = "Spooler"
'local var
Dim ObjectWmiService,ColServiceList,ObjectService,intReturnState
Set ObjectWmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set ColServiceList = ObjectWmiService.ExecQuery("Select * from Win32_Service where Name='" & strServiceName & "'")
For Each ObjectService In ColServiceList
WScript.Echo "Stop Service: " & ObjectService.caption
intReturnState = ObjectService.StopService()
WScript.Echo "Stop Service state is: " & StateOfService(intReturnState)
Next
End Function
Private Function StateOfService(pintReturnValue)
WScript.Echo pintReturnValue
Select Case pintReturnValue
Case 0 StateOfService = "Success"
Case 1 StateOfService = "Not Supported"
Case 2 StateOfService = "Access Denied"
Case 3 StateOfService = "Dependent Services Running"
Case 4 StateOfService = "Invalid Service Control"
Case 5 StateOfService = "Service Cannot Accept Control"
Case 6 StateOfService = "Service Not Active"
Case 7 StateOfService = "Service Request timeout"
Case 8 StateOfService = "Unknown Failure"
Case 9 StateOfService = "Path Not Found"
Case 10 StateOfService = "Service Already Stopped"
Case 11 StateOfService = "Service Database Locked"
Case 12 StateOfService = "Service Dependency Deleted"
Case 13 StateOfService = "Service Dependency Failure"
Case 14 StateOfService = "Service Disabled"
Case 15 StateOfService = "Service Logon Failed"
Case 16 StateOfService = "Service Marked For Deletion"
Case 17 StateOfService = "Service No Thread"
Case 18 StateOfService = "Status Circular Dependency"
Case 19 StateOfService = "Status Duplicate Name"
Case 20 StateOfService = "Status - Invalid Name"
Case 21 StateOfService = "Status - Invalid Parameter"
Case 22 StateOfService = "Status - Invalid Service Account"
Case 23 StateOfService = "Status - Service Exists"
Case 24 StateOfService = "Service Already Paused"
Case Else StateOfService = "Uknow Code"
End Select
End Function |
Partager