News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

WTS Structure Wrong?

Started by AgentSmithers, September 02, 2011, 02:25:37 AM

Previous topic - Next topic

dedndave

that is not what i see in the documentation, at all - lol

WTS_SESSION_INFO STRUCT
  SessionId       dd ?
  pWinStationName LPTSTR ?
  State           WTS_CONNECTSTATE_CLASS <>
WTS_SESSION_INFO ENDS


not sure about the last member - lol
it appears to be a constant, so dword is probably right   :P

MichaelW

WTS_CONNECTSTATE_CLASS is an enumeration:

typedef enum _WTS_CONNECTSTATE_CLASS {
    WTSActive,              // User logged on to WinStation
    WTSConnected,           // WinStation connected to client
    WTSConnectQuery,        // In the process of connecting to client
    WTSShadow,              // Shadowing another WinStation
    WTSDisconnected,        // WinStation logged on without client
    WTSIdle,                // Waiting for client to connect
    WTSListen,              // WinStation is listening for connection
    WTSReset,               // WinStation is being reset
    WTSDown,                // WinStation is down due to error
    WTSInit,                // WinStation in initialization
} WTS_CONNECTSTATE_CLASS;


Each symbol stands for an integer value, WTSActive=0, WTSConnected=1, etc, and VC2003 sees the size of the field as 4 bytes.
eschew obfuscation

AgentSmithers

I got it -.-

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\Ws2_32.inc
include \masm32\include\advapi32.inc
include \masm32\include\wtsapi32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\Ws2_32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\wtsapi32.lib

include \masm32\include\masm32.inc
include \masm32\include\debug.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\debug.lib

WTS_SESSION_INFO STRUCT
  SessionId             DWORD      ?
  pWinStationName       DWORD      ?
  State                 DWORD      ?
WTS_SESSION_INFO ENDS

.data
ServerName db "Hostname", 0

.data?
ServerHandle dd ?
Count dd ?
ppSessionInfo dd ?

.code

start:

invoke WTSOpenServerA, ADDR ServerName
mov ServerHandle, EAX
invoke WTSEnumerateSessions, EAX, 0, 1, OFFSET ppSessionInfo, ADDR Count

mov eax, [ppSessionInfo]

mov ECX, Count
.WHILE ECX!=0
    mov ebx, [eax+4]
    add eax, SIZEOF(WTS_SESSION_INFO)
    DEC ECX
.ENDW


end start

dedndave

it takes a while to return, huh - lol

i did a little clean-up   :P
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\Ws2_32.inc
        INCLUDE    \masm32\include\wtsapi32.inc
        INCLUDELIB \masm32\lib\Ws2_32.lib
        INCLUDELIB \masm32\lib\wtsapi32.lib

WTS_SESSION_INFO STRUCT
  SessionId        dd ?
  pWinStationName  LPSTR ?
  State            dd ?
WTS_SESSION_INFO ENDS

        .DATA

szServerName db 'Hostname',0

        .DATA?

hServer      dd ?
Count        dd ?
pSessionInfo dd ?

        .CODE

_main   PROC

        INVOKE  WTSOpenServer,offset szServerName
        mov     hServer,eax
        INVOKE  WTSEnumerateSessions,eax,0,1,offset pSessionInfo,offset Count
        mov     esi,pSessionInfo
        mov     ebx,Count

loop00: mov     eax,[esi].WTS_SESSION_INFO.pWinStationName
        print   eax
        print   chr$(13,10)
        add     esi,sizeof WTS_SESSION_INFO
        dec     ebx
        jnz     loop00

        INVOKE  WTSCloseServer,hServer
        inkey
        exit

_main   ENDP

        END     _main

dedndave

for the current server, you can use WTS_CURRENT_SERVER_HANDLE
much faster   :U
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\Ws2_32.inc
        INCLUDE    \masm32\include\wtsapi32.inc
        INCLUDELIB \masm32\lib\Ws2_32.lib
        INCLUDELIB \masm32\lib\wtsapi32.lib

WTS_CURRENT_SERVER_HANDLE EQU 0

WTS_SESSION_INFO STRUCT
  SessionId        dd ?
  pWinStationName  LPSTR ?
  State            dd ?
WTS_SESSION_INFO ENDS

        .DATA?

Count        dd ?
pSessionInfo dd ?

        .CODE

_main   PROC

        INVOKE  WTSEnumerateSessions,WTS_CURRENT_SERVER_HANDLE,0,1,offset pSessionInfo,offset Count
        mov     esi,pSessionInfo
        mov     ebx,Count
        print   str$(ebx),13,10

loop00: mov     eax,[esi].WTS_SESSION_INFO.pWinStationName
        print   eax
        print   chr$(13,10)
        add     esi,sizeof WTS_SESSION_INFO
        dec     ebx
        jnz     loop00

        inkey
        exit

_main   ENDP

        END     _main