Ontosy

Error 6: ERROR_INVALID_HANDLE

6 posts in this topic

when i use "__QueryServiceStatus" from _NTServices.au3 i obtain a
 "Error 6: ERROR_INVALID_HANDLE".

I obtain same error also when use this dll.

from what may depend?

Share this post


Link to post
Share on other sites



If _NTServices.au3 is from this old example then there are a number of issues in the implementation of the functions. For example that handles are stored as integer data types in DllCalls. This means that the UDF will not work on 64 bit. And all the functions seems to be the ansi version (A-functions). Today you would use the unicode version (W-functions). If you go through the entire UDF and corrects all the mistakes, I'm pretty sure it'll work.

Share this post


Link to post
Share on other sites

Same script work in Win7 x64 and not in Win10 x64.

I not know if it is a SO or SO setting.

I not know how investigate it.

Share this post


Link to post
Share on other sites

It takes a few months before I get access to a Windows 10 PC. Perhaps there is another who can look at it. I'm almost sure it'll work if the functions are implemented properly.

Share this post


Link to post
Share on other sites

Hello. As LarsJ says funtions are not implemented properly. So I wrote this example with correct implementation. (tested in windows 10 x64. Compiled as x86 and x64)

 

Global Const $sTagSERVICE_STATUS = "DWORD dwServiceType;" & _
        "DWORD dwCurrentState;" & _
        "DWORD dwControlsAccepted;" & _
        "DWORD dwWin32ExitCode;" & _
        "DWORD dwServiceSpecificExitCode;" & _
        "DWORD dwCheckPoint;" & _
        "DWORD dwWaitHint;"




Global $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 Const $hAdvapi32 = DllOpen("advapi32.dll")

MsgBox(64, "Info", "Make sure youre running Admin")


Local $aRet = 0
Local $sServiceName = "Spooler"

$aRet = DllCall($hAdvapi32, "handle", "OpenSCManagerW", _
        "wstr", Null, _
        "wstr", Null, _
        "dword", $SC_MANAGER_ALL_ACCESS)

If $aRet[0] = 0 Then
    If $aRet[0] = 0 And Not @error Then ConsoleWrite("!Error in OpenSCManager" & @CRLF)
    Exit
EndIf

Local $hSCManager = $aRet[0]

;~ MsgBox(0, "", $hSCManager)
ConsoleWrite(">$hSCManager: " & $hSCManager & @CRLF)

$aRet = DllCall($hAdvapi32, "handle", "OpenServiceW", _
        "handle",$hSCManager, _
        "wstr", $sServiceName, _
        "long", $SC_MANAGER_ALL_ACCESS)

If $aRet[0] = 0 Then
    If $aRet[0] = 0 And Not @error Then ConsoleWrite("!Error in OpenServiceW" & @CRLF)
    Exit
EndIf

Local $hServ = $aRet[0]
;~ MsgBox(0, "", $hServ)
ConsoleWrite(">$hSCManager: " & $hServ & @CRLF)


Local $tStatus = DllStructCreate($sTagSERVICE_STATUS)

$aRet = DllCall($hAdvapi32, "bool", "QueryServiceStatus", _
        "handle", $hServ, _
        "ptr", DllStructGetPtr($tStatus))

If $aRet[0] = 0 Then
    If $aRet[0] = 0 And Not @error Then ConsoleWrite("!Error in QueryServiceStatus" & @CRLF)
    Exit
EndIf

ConsoleWrite("+Spooler Status: " & $tStatus.dwCurrentState & @CRLF)
MsgBox(0, "", "Spooler Status: " & $tStatus.dwCurrentState)


DllCall($hAdvapi32, "bool", "CloseServiceHandle", "handle", $hServ)
DllCall($hAdvapi32, "bool", "CloseServiceHandle", "handle", $hSCManager)
DllClose($hAdvapi32)

Saludos

2 people like this

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ty, now it is works.

Edited by Ontosy

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