Jump to content
Sign in to follow this  
gte

Can you call advapi32.dll over the network?

Recommended Posts

gte

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.

;===============================================================================
;[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

_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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.