gte Posted January 31, 2010 Posted January 31, 2010 expandcollapse popupGlobal $STANDARD_RIGHTS_REQUIRED = 0x000F0000 Global $SC_MANAGER_CONNECT = 0x0001 Global $SC_MANAGER_CREATE_SERVICE = 0x0002 Global $SC_MANAGER_ENUMERATE_SERVICE = 0x0004 Global $SC_MANAGER_LOCK = 0x0008 Global $SC_MANAGER_QUERY_LOCK_STATUS = 0x0010 Global $SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020 Global $SC_MANAGER_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _ $SC_MANAGER_CONNECT, _ $SC_MANAGER_CREATE_SERVICE, _ $SC_MANAGER_ENUMERATE_SERVICE, _ $SC_MANAGER_LOCK, _ $SC_MANAGER_QUERY_LOCK_STATUS, _ $SC_MANAGER_MODIFY_BOOT_CONFIG) Global $SERVICE_QUERY_CONFIG = 0x0001 Global $SERVICE_CHANGE_CONFIG = 0x0002 Global $SERVICE_QUERY_STATUS = 0x0004 Global $SERVICE_ENUMERATE_DEPENDENTS = 0x0008 Global $SERVICE_START = 0x0010 Global $SERVICE_STOP = 0x0020 Global $SERVICE_PAUSE_CONTINUE = 0x0040 Global $SERVICE_INTERROGATE = 0x0080 Global $SERVICE_USER_DEFINED_CONTROL = 0x0100 Global $SERVICE_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _ $SERVICE_QUERY_CONFIG, _ $SERVICE_CHANGE_CONFIG, _ $SERVICE_QUERY_STATUS, _ $SERVICE_ENUMERATE_DEPENDENTS, _ $SERVICE_START, _ $SERVICE_STOP, _ $SERVICE_PAUSE_CONTINUE, _ $SERVICE_INTERROGATE, _ $SERVICE_USER_DEFINED_CONTROL) Global $SERVICE_CONTROL_STOP = 0x00000001 Global $SERVICE_CONTROL_INTERROGATE = 0x00000004 $bRunning = "" $server = "" ;~ if _ServiceRunning("Alerter") = 1 Then ;~ MsgBox(0,0,"Running") ;~ ElseIf _ServiceRunning("Alerter") = 0 Then ;~ MsgBox(0,0,"Not Running") ;~ EndIf ;=============================================================================== ; ; Description: Checks to see if a service is running ; Syntax: _ServiceRunning($sServiceName) ; Parameter(s): $sServiceName - Name of service to check ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; Author(s): SumTingWong ; Documented by: noone ; ;=============================================================================== Func _ServiceRunning($sServiceName) Local $arRet Local $hSC Local $hService Local $bRunning = 0 $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _ "str", "", _ "str", "ServicesActive", _ "long", $SC_MANAGER_CONNECT) If $arRet[0] <> 0 Then $hSC = $arRet[0] $arRet = DllCall("advapi32.dll", "long", "OpenService", _ "long", $hSC, _ "str", $sServiceName, _ "long", $SERVICE_INTERROGATE) If $arRet[0] <> 0 Then $hService = $arRet[0] $arRet = DllCall("advapi32.dll", "int", "ControlService", _ "long", $hService, _ "long", $SERVICE_CONTROL_INTERROGATE, _ "str", "") $bRunning = $arRet[0] DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService) EndIf DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC) EndIf Return $bRunning EndFunc Like this below? expandcollapse popupGlobal $STANDARD_RIGHTS_REQUIRED = 0x000F0000 Global $SC_MANAGER_CONNECT = 0x0001 Global $SC_MANAGER_CREATE_SERVICE = 0x0002 Global $SC_MANAGER_ENUMERATE_SERVICE = 0x0004 Global $SC_MANAGER_LOCK = 0x0008 Global $SC_MANAGER_QUERY_LOCK_STATUS = 0x0010 Global $SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020 Global $SC_MANAGER_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _ $SC_MANAGER_CONNECT, _ $SC_MANAGER_CREATE_SERVICE, _ $SC_MANAGER_ENUMERATE_SERVICE, _ $SC_MANAGER_LOCK, _ $SC_MANAGER_QUERY_LOCK_STATUS, _ $SC_MANAGER_MODIFY_BOOT_CONFIG) Global $SERVICE_QUERY_CONFIG = 0x0001 Global $SERVICE_CHANGE_CONFIG = 0x0002 Global $SERVICE_QUERY_STATUS = 0x0004 Global $SERVICE_ENUMERATE_DEPENDENTS = 0x0008 Global $SERVICE_START = 0x0010 Global $SERVICE_STOP = 0x0020 Global $SERVICE_PAUSE_CONTINUE = 0x0040 Global $SERVICE_INTERROGATE = 0x0080 Global $SERVICE_USER_DEFINED_CONTROL = 0x0100 Global $SERVICE_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _ $SERVICE_QUERY_CONFIG, _ $SERVICE_CHANGE_CONFIG, _ $SERVICE_QUERY_STATUS, _ $SERVICE_ENUMERATE_DEPENDENTS, _ $SERVICE_START, _ $SERVICE_STOP, _ $SERVICE_PAUSE_CONTINUE, _ $SERVICE_INTERROGATE, _ $SERVICE_USER_DEFINED_CONTROL) Global $SERVICE_CONTROL_STOP = 0x00000001 Global $SERVICE_CONTROL_INTERROGATE = 0x00000004 $bRunning = "" $server = "[MACHINE NAME" ;~ _ServiceRunning("FECS NOTIFICATION") _ServiceRunning("Alerter") Func _ServiceRunning($sServiceName) Local $arRet Local $hSC Local $hService Local $bRunning = 0 $arRet = DllCall("\\" & $server & "\" & @WindowsDir & "\advapi32.dll", "long", "OpenSCManager", _ "str", "", _ "str", "ServicesActive", _ "long", $SC_MANAGER_CONNECT) If $arRet[0] <> 0 Then $hSC = $arRet[0] $arRet = DllCall("\\" & $server & "\" & @WindowsDir & "\advapi32.dll", "long", "OpenService", _ "long", $hSC, _ "str", $sServiceName, _ "long", $SERVICE_INTERROGATE) If $arRet[0] <> 0 Then $hService = $arRet[0] $arRet = DllCall("\\" & $server & "\" & @WindowsDir & "\advapi32.dll", "int", "ControlService", _ "long", $hService, _ "long", $SERVICE_CONTROL_INTERROGATE, _ "str", "") $bRunning = $arRet[0] DllCall("\\" & $server & "\" & @WindowsDir & "\advapi32.dll", "int", "CloseServiceHandle", "long", $hService) EndIf DllCall("\\" & $server & "\" & @WindowsDir & "\advapi32.dll", "int", "CloseServiceHandle", "long", $hSC) EndIf ConsoleWrite("Function return for service is " & $bRunning & @CRLF) Return $bRunning EndFunc HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script
gte Posted January 31, 2010 Author Posted January 31, 2010 Can I put the $server in this location? It appears to have worked, but I'm not 100% sure it did$arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _ "str", $server, _ "str", "ServicesActive", _ "long", $SC_MANAGER_CONNECT) HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now