Purpose: I
am trying to gather connection information from Terminal Server across our
enterprise. Microsoft has released docs for there wtsapi32.dll which will
provide this information. Problem: The
function WTSEnumerateSessions returns a pointer to an
array of structures. The variable that receives the return value from the
function call gets the address as a value rather than a memory pointer. Here
is some detail, Step 1.
Obtain a handle to the server that I want to query. Function to use: HANDLE WTSOpenServer(LPTSTR
pServerName); My $WTSOpenServer =
new Win32::API("wtsapi32.dll", "WTSOpenServer",[P],N) Or die 'Find WTSOpenServer: ' . ErrMsg (); My $hServer = $WTSOpenServer->Call('SOMESERVERNAME') Or die 'Call WTSOpenServer: ' . ErrMsg (); Step 2.
Call the EnumerateSession Function with handle and
get pointer to array of sessions my
$SessionInfo = pack 'A*',"\x00" x 16; my
$Count = pack 'I',0; my
$WTSEnumerateSessions = new
Win32::API('wtsapi32.dll', 'WTSEnumerateSessions',[qw(N N N
P P)],'I') or
die 'Find WTSEnumerateSessions: ' . ErrMsg (); my
$rv = $WTSEnumerateSessions->Call($hServer,0,1,$SessionInfo,$Count); die
'Call WTSEnumerateSessions: ' . ErrMsg
() if (!$rv); Step 3.
Print out the contents of the SessionInfo Array of
structures. There is where I
do not know where to go. Prototypes
from Microsoft: BOOL WTSEnumerateSessions( HANDLE hServer, DWORD Reserved, DWORD Version, >>>>PWTS_SESSION_INFO* ppSessionInfo, DWORD* pCount ); This function takes five parameters; the
first three are straight forward. >hServer - is a handle to an open session. This one works fine
>Reserved
- Version - must be 1 The next two are variables will return
the address of the data. If the Return ppSessionInfo
is a pointer, would I get at the values like this? This
does not seem to work. my ($SessionID,$StationName,$State) = unpack("IPI",$SessionInfo); The pointer returns an array of these
structures. >
typedef struct
_WTS_SESSION_INFO { >
DWORD SessionId; >
LPTSTR pWinStationName; >
WTS_CONNECTSTATE_CLASS
State; >
} WTS_SESSION_INFO,
*PWTS_SESSION_INFO; |
- RE: Trying to get Terminal Server Session Info w... Morgan, Steve H.
- RE: Trying to get Terminal Server Session I... Krummel, James C - PGGC-6