# Using WTSQuerySessionInformation to get client computer name when running in a remote session

**URL:** <https://clarionhub.com/t/using-wtsquerysessioninformation-to-get-client-computer-name-when-running-in-a-remote-session/4441>\
**Category:** code\
**Tags:** api, code\
**Created:** [September 1, 2021, 10:37pm UTC](https://clarionhub.com/t/using-wtsquerysessioninformation-to-get-client-computer-name-when-running-in-a-remote-session/4441 "2021-09-01T22:37:50Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [September 3, 2021, 3:03pm UTC](https://clarionhub.com/t/using-wtsquerysessioninformation-to-get-client-computer-name-when-running-in-a-remote-session/4441/8 "2021-09-03T15:03:25Z")

</div>

Very interesting discussion.  
I agree with Jeff, you should not make any assumptions about the memory contents past the buffer length returned by any API.  
Additionally, the call to WTSQuerySessionInformation does not just return the address of null terminated strings in BufferRef. It can be the offset of structures like WTSClient, WTSInfo, WTSConfigInfo, etc.

Turns out there is a bug in my original code. The BufferLength returned by the call includes the trailing NULL character. My workstation name is DIMHOLT which is 7 characters. BufferLength is returning 8 when I call to get the client name. No harm in the bug, other than allocating an extra byte of memory for a few milliseconds.

I thought it might be interesting to show how I examined the memory returned by the API call to answer the question of the buffer length and NULL character. Here’s an explanation of the techniques.

> [@Using the Clarion Debugger to examine memory and follow memory offsets](https://clarionhub.com/t/using-the-clarion-debugger-to-examine-memory-and-follow-memory-offsets/4443):
>
> Over in this thread, ([https://clarionhub.com/t/using-wtsquerysessioninformation-to-get-client-computer-name-when-running-in-a-remote-session/4441/8](https://clarionhub.com/t/using-wtsquerysessioninformation-to-get-client-computer-name-when-running-in-a-remote-session/4441/8)) a few of us are discussing the use of WTSQuerySessionInformation. This API returns a address that is the offset to the return information. In this case, the return information was a null terminated string (CSTRING) and it was uncertain if the returned buffer length included the NULL character or not. I fired up the debugger to examine the data and …

---

_[View the full topic](https://clarionhub.com/t/using-wtsquerysessioninformation-to-get-client-computer-name-when-running-in-a-remote-session/4441)._
