supersonic

DllCall doesn't return data!?

16 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Monkey's are, like, natures humans.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

JohnOne,

thank you. I forgot to use DllStructGetPtr() in the 2nd DllCall and now a valid (?) ptr returns...

But how to go on to get the desired data...?

 

Share this post


Link to post
Share on other sites

You should use the structure $tTmp instead $tagWINSTATIONINFORMATIONW.

 

Saludos

Share this post


Link to post
Share on other sites

Danyfirex,

I don't know to do better: How should $tagWINSTATIONINFORMATIONW look like?

 

Share this post


Link to post
Share on other sites

My fault - of course I have to use DllStructGetData($tTmp, ...) :>

Still no data returns; is the structure correct? What is the equiv. for "FILETIME" in AutoIt?

Share this post


Link to post
Share on other sites

#10 ·  Posted

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

1 person likes this

Share this post


Link to post
Share on other sites

#12 ·  Posted

Share this post


Link to post
Share on other sites

#13 ·  Posted

@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 ?

Share this post


Link to post
Share on other sites

#14 ·  Posted

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))

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

 

Saludos

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