gte Posted November 16, 2009 Share Posted November 16, 2009 I'm trying to modify the first function to work over the network (second function) and if I call the advapi32 on a network machine, it returns the status of the service I'm calling on a local machine. Is there a way to do this? I did not write the original function, and I am not very familiar with dll calls. expandcollapse popup;=============================================================================== ;[right][/right] ; 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 ; ;=============================================================================== _ServiceRunning2("Alerter") Func _ServiceRunning2($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] MsgBox(0, "hSC2", $hSC) $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 MsgBox(0, "bRunning", $bRunning) Return $bRunning EndFunc expandcollapse popup_ServiceRunning("Alerter", "[machinename]") Func _ServiceRunning($sServiceName, $server) Local $arRet Local $hSC Local $hService Local $bRunning = 0 $arRet = DllCall("\\" & $server & "\c$\winnt\system32\advapi32.dll", "long", "OpenSCManager", _ "str", "", _ "str", "ServicesActive", _ "long", $SC_MANAGER_CONNECT) If $arRet[0] <> 0 Then $hSC = $arRet[0] MsgBox(0, "hSC", $hSC) $arRet = DllCall("\\" & $server & "\c$\winnt\system32\advapi32.dll", "long", "OpenService", _ "long", $hSC, _ "str", $sServiceName, _ "long", $SERVICE_INTERROGATE) If $arRet[0] <> 0 Then $hService = $arRet[0] $arRet = DllCall("\\" & $server & "\c$\winnt\system32\advapi32.dll", "int", "ControlService", _ "long", $hService, _ "long", $SERVICE_CONTROL_INTERROGATE, _ "str", "") $bRunning = $arRet[0] DllCall("\\" & $server & "\c$\winnt\system32\advapi32.dll", "int", "CloseServiceHandle", "long", $hService) EndIf DllCall("\\" & $server & "\c$\winnt\system32\advapi32.dll", "int", "CloseServiceHandle", "long", $hSC) EndIf MsgBox(0, "bRunning", $bRunning) Return $bRunning EndFunc HP OpenView ServiceCenter keep alive scriptRemote Desktop Login Script Link to comment Share on other sites More sharing options...
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