I am remotely connecting to Windows 10 Client OS through RDP client. When I collected WTSIsRemoteSession and WTSClientProtocolType using WTSQuerySessionInformationW() I correctly received that it was a remote session and protocol was RDP. However, when I tried to collect Client info as follows, the condition for AF_INET fails and Client Device Id is also blank. Need to know what I may be missing here.
I noticed that all of the PWTSCLIENTA data was null. Strange thing was that, the query function itself did not fail.Following is my code.
if (WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientInfo, &pData, &bytesReturned)){
PWTSCLIENTA address = (PWTSCLIENTA)pData;
printf("\tWTSQuerySessionInformationW - session %d - %s returned \"%p\"\n", WTS_CURRENT_SESSION, "WTSClientInfo", pData);
if (AF_INET == address->ClientAddressFamily)
{
printf("\n\tClient Address : %d.%d.%d.%d\n", address->ClientAddress[2], address->ClientAddress[3], address->ClientAddress[4], address->ClientAddress[5]);
}
printf("\tClient DeviceId : %s\n\n", address->DeviceId);
}
You are calling
WTSQuerySessionInformationW(), but you are castingpDatatoPWTSCLIENTAwhen you need to cast it toPWTSCLIENTWinstead. As such, you are accessing theClientAddressFamily,ClientAddress, andDeviceIdfields using the wrong byte offsets.Also, make sure you handle the possibility of the
ClientAddressFamilybeingAF_INET6instead ofAF_INET.Try something more like this: