Jump to content

DllCall doesn't return data!?


Recommended Posts

Hi,

I'm trying to fetch some data from out terminal server (connection time, login time, etc.). Therefore the DLL winsta.dll can be used. Although searching the web for any help on this, I'm still failing to return any useful data. That's what I have so far:

#include <Array.au3>

Local $sServerName = @ComputerName
Local $iSessionId = 0

Local $aResult = DllCall("wtsapi32.dll", "HANDLE", "WTSOpenServerA", "STR", $sServerName)
If (Not @error) Then
    
    Local Const $hServer = $aResult[0]
    Local Const $tagWINSTATIONINFORMATIONW = _
            "BYTE Reserved1[72];" & _
            "ULONG SessionId;" & _
            "BYTE Reserved2[4];" & _
            "CHAR ConnectTime;" & _
            "CHAR DisconnectTime;" & _
            "CHAR LastInputTime;" & _
            "CHAR LoginTime;" & _
            "BYTE Reserved3[1096];" & _
            "CHAR CurrentTime;"
    Local $tTmp = DllStructCreate($tagWINSTATIONINFORMATIONW)

    $aResult = DllCall("winsta.dll", "BOOL", "WinStationQueryInformationW", "HANDLE", $hServer, "DWORD", $iSessionId, "DWORD", 8, "PTR", $tTmp, "DWORD", DllStructGetSize($tTmp), "PTR*", 0)
    If (Not @error) Then
        _ArrayDisplay($aResult)
        MsgBox(0, "", DllStructGetData($tagWINSTATIONINFORMATIONW, 5))
    EndIf

EndIf

MSDN: https://msdn.microsoft.com/en-us/library/aa383827(v=VS.85).aspx .

The call returns "some" results, but how to extract the data from the structure?

S.

Edited by supersonic
Link to comment
Share on other sites

Do a quick sanity test.

DllCall("winsta.dll", "BOOL", "WinStationQueryInformationW", "HANDLE", $hServer, "DWORD", $aData[2][1], "DWORD", 8, "PTR", DllStructgetPtr($tTmp), "DWORD", DllStructGetSize($tTmp), "PTR*", 0)

arg 4should be void pointer?

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Also check your structure. It should be something like this:

 

typedef struct _WINSTATIONQUERYINFORMATION
{
    char Reserved1[72];
    unsigned int SessionId;
    char Reserved2[4];
    FILETIME ConnectTime;
    FILETIME DisconnectTime;
    FILETIME LastInputTime;
    FILETIME LogonTime;
    char Reserved3[1096];
    FILETIME CurrentTime;
} WINSTATIONQUERYINFORMATION, *PWINSTATIONQUERYINFORMATION;

Saludos

Link to comment
Share on other sites

You should use the structure $tTmp instead $tagWINSTATIONINFORMATIONW.

 

Saludos

Link to comment
Share on other sites

Structure should look like:

Local Const $tagWINSTATIONINFORMATIONW = _
        "char Reserved1[72];" & _
        "uint SessionId;" & _
        "char Reserved2[4];" & _
        "dword;dword;" & _
        "dword;dword;" & _
        "dword;dword;" & _
        "dword;dword;" & _
        "char Reserved3[1096];" & _
        "dword;dword;"

 

dword;dword are FILETIME structure.

 

Saludos

Link to comment
Share on other sites

@Danyfirex : I thought we should use something like this :

Local Const $tagWINSTATIONINFORMATIONW = _
        "char Reserved1[72];" & _
        "uint SessionId;" & _
        "char Reserved2[4];" & _
        "struct,dword;dword;endstruct;" & _
        "struct,dword;dword;endstruct;" & _
        "struct,dword;dword;endstruct;" & _
        "struct,dword;dword;endstruct;" & _
        "char Reserved3[1096];" & _
        "struct,dword;dword;endstruct;"

is it the same thing ?

Link to comment
Share on other sites

Perfect! :) Thank you all.

I ended up with this:

; ...

Local Const $tagWINSTATIONINFORMATIONW = _
        "char Reserved1[72];" & _
        "uint SessionId;" & _
        "char Reserved2[4];" & _
        "struct; dword; dword; endstruct;" & _
        "struct; dword; dword; endstruct;" & _
        "struct; dword; dword; endstruct;" & _
        "struct; dword; dword; endstruct;" & _
        "char Reserved3[1096];" & _
        "struct; dword; dword; endstruct;"
        
; ...

        Local $tFILETIME = DllStructCreate($tagFILETIME)
        DllStructSetData($tFILETIME, 1, DllStructGetData($tTmp, 13))
        DllStructSetData($tFILETIME, 2, DllStructGetData($tTmp, 14))
        MsgBox(0, "", _Date_Time_FileTimeToStr($tFileTime))

 

Link to comment
Share on other sites

@jguinch It will not work because you use "," after struct  haha :D.    Using ";"  Its same as mine.

 

Saludos

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...