Jump to content

[Solved] struct _WTSINFO


Recommended Posts

..where to start. I've posted: 

now I wanna pull the data from WTSSessionInfo and WTSSessionInfoEx as described in https://docs.microsoft.com/en-us/windows/win32/api/wtsapi32/ns-wtsapi32-wtsinfoa

typedef struct _WTSINFOA {
  WTS_CONNECTSTATE_CLASS State; <--- that is an enumeration from https://docs.microsoft.com/en-us/windows/win32/api/wtsapi32/ne-wtsapi32-wts_connectstate_class
  DWORD                  SessionId;
  DWORD                  IncomingBytes;
  DWORD                  OutgoingBytes;
  DWORD                  IncomingFrames;
  DWORD                  OutgoingFrames;
  DWORD                  IncomingCompressedBytes;
  DWORD                  OutgoingCompressedBy;
  CHAR                   WinStationName[WINSTATIONNAME_LENGTH];
  CHAR                   Domain[DOMAIN_LENGTH];
  CHAR                   UserName[USERNAME_LENGTH + 1];
  LARGE_INTEGER          ConnectTime;
  LARGE_INTEGER          DisconnectTime;
  LARGE_INTEGER          LastInputTime;
  LARGE_INTEGER          LogonTime;
  LARGE_INTEGER          CurrentTime;
} WTSINFOA, *PWTSINFOA;

from the example in ListUserSessions() I get, say:

24  WTSSessionInfo _________ 0x00000000070000000D930F00229CDD00000000000000000000000000000000005244502D5463702331313700000000000000000000000000000000000000000050433032370000000000000000000000006C756973790000000000000000000000000000000000002174A0FB1B0AD70100000000000000000625AF0A200AD701AF99E5FB1B0AD701A56FBA0A200AD701
25  WTSSessionInfoEx _______ 0x01000000000000000700000000000000010000005244502D54637023313137000000000000000000000000000000000000000000006C756973790000000000000000000000000000000050433032370000000000000000000000000000000000AF99E5FB1B0AD7012174A0FB1B0AD70100000000000000000625AF0A200AD701BBBDBA0A200AD7010D930F00229CDD0000000000000000000000000000000000

My question is: how do I get the binary example above ( WTSSessionInfo ) into a struct to DllStructGetData().

Thanks

Solution at https://www.autoitscript.com/forum/topic/205232-struct-_wtsinfo/?do=findComment&comment=1475912  :) 

 

Edited by argumentum
solved

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

You can read out the binary value of WTSSessionInfo and put it to a ubyte array struct. Afterwards just create the _WTSINFOA and map it the binary string.

Something like this here:

Global $a = ListUserSessions()

$t24 = DllStructCreate("ubyte mem[" & BinaryLen(_WTSQuerySessionInformation($i, 24, 1)) / 2 & "]")
$t24.mem = _WTSQuerySessionInformation($i, 24, 1)
$tag = "int State;dword State;dword IncomingBytes;dword OutgoingBytes;dword IncomingFrames;dword OutgoingFrames;dword IncomingCompressedBytes;dword OutgoingCompressedBy;" & _
                              "ubyte WinStationName[12];ubyte Domain[3];ubyte UserName[7];int64 ConnectTime;int64 DisconnectTime;int64 LastInputTime;int64 LogonTime;int64 LogonTime"
$t = DllStructCreate($tag, DllStructGetPtr($t24))
_WinAPI_DisplayStruct($t, $tag)

You have to set the length of arrays WinStationName, Domain and UserName accordingly.

 

I hope it helps.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

..I'm fighting with the 

CHAR                   WinStationName[WINSTATIONNAME_LENGTH];
  CHAR                   Domain[DOMAIN_LENGTH];
  CHAR                   UserName[USERNAME_LENGTH + 1];

part of it

#include <WinAPIDiag.au3>

Test()
Func Test()
    Local $d24 = "0x00000000070000000D930F00229CDD000000000000000000000000000000" & _
            "00005244502D546370233131370000000000000000000000000000000000000000005043303237" & _
            "0000000000000000000000006C756973790000000000000000000000000000000000002174A0FB" & _
            "1B0AD70100000000000000000625AF0A200AD701AF99E5FB1B0AD701A56FBA0A200AD701"
    $d24 = BinaryToString($d24)

    ConsoleWrite(StringReplace($d24, Chr(0), "") & @CRLF) ; to see what strings should I find

    Local $t24 = DllStructCreate("ubyte mem[" & BinaryLen($d24) / 2 & "]")
    $t24.mem = $d24
    Local $tag = "int State;dword SessionId;dword IncomingBytes;dword OutgoingBytes;dword IncomingFrames;" & _
            "dword OutgoingFrames;dword IncomingCompressedBytes;dword OutgoingCompressedBy;ubyte WinStationName[32]" & _
            ";ubyte Domain[8];ubyte UserName[20];int64 ConnectTime;int64 DisconnectTime;int64 LastInputTime;int64 LogonTime;int64 LogonTime"
    Local $t = DllStructCreate($tag, DllStructGetPtr($t24))
    ConsoleWrite("State          = " & $t.State & @CRLF)
    ConsoleWrite("SessionId      = " & $t.SessionId & @CRLF)

;~  ConsoleWrite("+WinStationName = " & BinaryToString($t.WinStationName) & @CRLF)
;~  ConsoleWrite("+Domain         = " & BinaryToString($t.Domain) & @CRLF)
;~  ConsoleWrite("+UserName       = " & BinaryToString($t.UserName) & @CRLF)

    ConsoleWrite("-WinStationName = " & StringReplace(BinaryToString($t.WinStationName), Chr(0), "") & @CRLF)
    ConsoleWrite("-Domain         = " & StringReplace(BinaryToString($t.Domain), Chr(0), "") & @CRLF)
    ConsoleWrite("-UserName       = " & StringReplace(BinaryToString($t.UserName), Chr(0), "") & @CRLF)
    _WinAPI_DisplayStruct($t, $tag)

EndFunc   ;==>Test

..I mean, WinStationName[????], where do I get the WINSTATIONNAME_LENGTH from ! :wacko2:, lol

It' not easy. But y'all got me closer than me on my own :gathering:

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Ok seems to be working well :

Local $sString = _WTSQuerySessionInformation($i, 24, 1)
Local $dData = Binary($sString)
ConsoleWrite ($dData & @CRLF)
$tByte = DllStructCreate("byte string[" & BinaryLen($dData) & "]")
Const $WINSTATIONNAME_LENGTH = 32
Const $DOMAIN_LENGTH = 17
Const $USERNAME_LENGTH = 20
DllStructSetData($tByte, 1, $dData)
Const $tagWTSINFOA = "BYTE state;DWORD SessionId;DWORD IncomingBytes;DWORD OutgoingBytes;DWORD IncomingFrames;DWORD OutgoingFrames;" & _
  "DWORD IncomingCompressedBytes;DWORD OutgoingCompressedBy;CHAR WinStationName[32];CHAR Domain[17];CHAR UserName[21];" & _
  "INT64 ConnectTime;INT64 DisconnectTime;INT64 LastInputTime;INT64 LogonTime;INT64 CurrentTime;"
$tWTSINFOA = DllStructCreate($tagWTSINFOA, DllStructGetPtr($tByte))
ConsoleWrite ($tWTSINFOA.WinStationName & @CRLF)

 

Link to comment
Share on other sites

cool, now, how do I make .LastInputTime readable ( human readable ).
It's supposed to be the count of ns. since 1601 UTC. ( https://docs.microsoft.com/en-us/dotnet/api/system.datetime.fromfiletime?view=net-5.0 )
But I can't find the way to do it
 

#include <WinAPIDiag.au3>
#include <Date.au3>

test2()
Func test2() ; https://www.autoitscript.com/forum/topic/205232-solved-struct-_wtsinfo/
    Local $dData = "0x00000000070000000D930F00229CDD000000000000000000000000000000" & _
            "00005244502D546370233131370000000000000000000000000000000000000000005043303237" & _
            "0000000000000000000000006C756973790000000000000000000000000000000000002174A0FB" & _
            "1B0AD70100000000000000000625AF0A200AD701AF99E5FB1B0AD701A56FBA0A200AD701"
    $dData = BinaryToString($dData)

;~  Local $dData = Binary(_WTSQuerySessionInformation($i, 24, 1))
    ConsoleWrite("=== ========================= ===" & @CRLF & StringReplace($dData, Chr(0), "") & @CRLF & "=== ========================= ===" & @CRLF)

    Local $tByte = DllStructCreate("byte string[" & BinaryLen($dData) & "]")
    Const $WINSTATIONNAME_LENGTH = 32
    Const $DOMAIN_LENGTH = 17
    Const $USERNAME_LENGTH = 20
    DllStructSetData($tByte, 1, $dData)
    Const $tagWTSINFOA = "struct;BYTE State;DWORD SessionId;DWORD IncomingBytes;DWORD OutgoingBytes;DWORD IncomingFrames;DWORD OutgoingFrames;" & _
            "DWORD IncomingCompressedBytes;DWORD OutgoingCompressedBy;CHAR WinStationName[32];CHAR Domain[17];CHAR UserName[21];" & _
            "INT64 ConnectTime;INT64 DisconnectTime;INT64 LastInputTime;INT64 LogonTime;INT64 CurrentTime;endstruct"
    Local $tWTSINFOA = DllStructCreate($tagWTSINFOA, DllStructGetPtr($tByte))

    ConsoleWrite("-State           = " & $tWTSINFOA.State & @CRLF)
    ConsoleWrite("-SessionId       = " & $tWTSINFOA.SessionId & @CRLF)
    ConsoleWrite("-WinStationName  = " & $tWTSINFOA.WinStationName & @CRLF)
    ConsoleWrite("-Domain          = " & $tWTSINFOA.Domain & @CRLF)
    ConsoleWrite("-UserName        = " & $tWTSINFOA.UserName & @CRLF)

    ; https://www.autoitscript.com/forum/topic/173626-having-trouble-converting-ad-datetime-to-readable-datetime/?do=findComment&comment=1256087
    ; @UEZ to the rescue   :)
    ConsoleWrite("-ConnectTime     = " & Systemtime2Datetime($tWTSINFOA.ConnectTime) & @CRLF)
    ConsoleWrite("-DisconnectTime  = " & Systemtime2Datetime($tWTSINFOA.DisconnectTime) & @CRLF)
    ConsoleWrite("-LastInputTime   = " & Systemtime2Datetime($tWTSINFOA.LastInputTime) & @CRLF)
    ConsoleWrite("-LogonTime       = " & Systemtime2Datetime($tWTSINFOA.LogonTime) & @CRLF)
    ConsoleWrite("-CurrentTime     = " & Systemtime2Datetime($tWTSINFOA.CurrentTime) & @CRLF)

    _WinAPI_DisplayStruct($tWTSINFOA, $tagWTSINFOA)
EndFunc   ;==>test2

Func Systemtime2Datetime($INT64) ; https://www.autoitscript.com/forum/topic/173626-having-trouble-converting-ad-datetime-to-readable-datetime/?do=findComment&comment=1256087
    If StringLen($INT64) < 8 Then Return SetError(1, 0, "")
    Return _DateAdd("s", StringTrimRight($INT64, 7), "1601/01/01 00:00:00")
EndFunc

solved :) 
Thanks @UEZ and @Nine
.

PS: @Nhardel, here is your answer too ;) 

Edited by argumentum
solved

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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

×
×
  • Create New...