Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Has anyone gotten WTSQuerySessionInformation API call from terminal services to work?

562 views
Skip to first unread message

Stephen Seltzer

unread,
May 8, 2003, 5:14:26 PM5/8/03
to
I am trying to get the client host name from a terminal services session.
The call is succeeding and it is returning back the correct number of bytes
in the pBytesReturned parameter (hostname length + 1 char) but the
information in the ppBuffer is not rendering correctly on the screen (it is
just garbage). Here is what I am doing:

Local External Functions:
Function Boolean WTSQuerySessionInformationA( uLong hServer, uLong
SessionId, uLong WTSInfoClass, Ref String ppBuffer, Ref uLong
pBytesReturned) Library "Wtsapi32.dll"


Script:
Boolean Success
Integer RetVal = 0
uLong ll_BuffLen = 256

//First we must initialize the string to 256 characters for API
compatability.
is_HostName = Space(256)

Success = WTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE,
WTS_CURRENT_SESSION, WTSClientName, is_HostName,ll_BuffLen)
MessageBox('Debug','HostName: ' + is_HostName + '~nSuccess: ' +
String(Success) + '~nBuffer Size: ' + String(ll_BuffLen))


Instance Variable Declarations:
String is_HostName
Private Constant uLong WTS_CURRENT_SERVER_HANDLE = 0
Private Constant uLong WTS_CURRENT_SESSION = -1

Private Constant uLong WTSInitialProgram = 0
Private Constant uLong WTSApplicationName = 1
Private Constant uLong WTSWorkingDirectory = 2
Private Constant uLong WTSOEMId = 3
Private Constant uLong WTSSessionId = 4
Private Constant uLong WTSUserName = 5
Private Constant uLong WTSWinStationName = 6
Private Constant uLong WTSDomainName = 7
Private Constant uLong WTSConnectState = 8
Private Constant uLong WTSClientBuildNumber = 9
Private Constant uLong WTSClientName = 10
Private Constant uLong WTSClientDirectory = 11
Private Constant uLong WTSClientProductId = 12
Private Constant uLong WTSClientHardwareId = 13
Private Constant uLong WTSClientAddress = 14
Private Constant uLong WTSClientDisplay = 15
Private Constant uLong WTSClientProtocolType = 16


TIA,
Steve


Stephen Seltzer

unread,
Jul 16, 2003, 2:26:32 PM7/16/03
to
I figured out what was happening and figured I would share with the group.
WTSQuerySessionInformationA returns a pointer to a string and not an actual
string. By changing the ppBuffer variable to a uLong I was able to get the
pointer. I then mapped:
SUBROUTINE WTSFreeMemory( ULONG pMemory ) Library "Wtsapi32.dll"
SUBROUTINE MoveMemoryPointerToString( REF String Destination, ULong
ul_Source, ULong ul_Size ) Library "KERNEL32.DLL" Alias For "RtlMoveMemory"

Where ul_Source gets the value from ppBuffer and ul_Size gets the value from
pBytesReturned.

I hope this helps someone!

Steve

"Stephen Seltzer" <ssel...@dsicdi.com> wrote in message
news:%23UsMHdaFDHA.222@forums-2-dub...

woz

unread,
Jul 16, 2003, 2:59:51 PM7/16/03
to
There is a little known thing in PB:

string(ll_pointer, "address")

It's used to make a string out of a powerobject pointer in message.longparm.

I wonder if this would have worked for you, too?

Generally, I feel the less external calls you make, the better. Wonder if this
could have worked for such a case?

Anatole Tartakovsky

unread,
Jul 16, 2003, 2:32:27 PM7/16/03
to
Another little known thing about string(ll_pointer, "address") is that PB
acquires lock on the memory that is never released - causing memory leak -
good for casual API use, but very dangerous for repeatabale communications.
Can be hard to notice with large memory/short testing, but definetly there
and problem with users using less memory and larger data sets
Regards,
Anatole
www.xmlsp.com


"woz" <ab...@msn.com> wrote in message news:3F15A0A7...@msn.com...

0 new messages