2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/error.h>
|
|
|
|
#include <winpr/wtsapi.h>
|
|
|
|
|
|
|
|
int TestWtsApiQuerySessionInformation(int argc, char* argv[])
|
|
|
|
{
|
2014-03-18 00:39:35 +04:00
|
|
|
DWORD index;
|
|
|
|
DWORD count;
|
2014-03-01 09:32:23 +04:00
|
|
|
BOOL bSuccess;
|
|
|
|
HANDLE hServer;
|
|
|
|
LPSTR pBuffer;
|
|
|
|
DWORD sessionId;
|
|
|
|
DWORD bytesReturned;
|
2014-03-18 00:39:35 +04:00
|
|
|
PWTS_SESSION_INFO pSessionInfo;
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
hServer = WTS_CURRENT_SERVER_HANDLE;
|
|
|
|
|
2014-03-18 00:39:35 +04:00
|
|
|
count = 0;
|
|
|
|
pSessionInfo = NULL;
|
2014-03-01 09:32:23 +04:00
|
|
|
|
2014-03-18 00:39:35 +04:00
|
|
|
bSuccess = WTSEnumerateSessions(hServer, 0, 1, &pSessionInfo, &count);
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
2014-03-18 00:39:35 +04:00
|
|
|
printf("WTSEnumerateSessions failed: %d\n", (int) GetLastError());
|
2014-04-28 05:54:21 +04:00
|
|
|
return 0;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
|
|
|
|
2014-03-18 00:39:35 +04:00
|
|
|
printf("WTSEnumerateSessions count: %d\n", (int) count);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
char* Username;
|
|
|
|
char* Domain;
|
|
|
|
char* ClientName;
|
|
|
|
ULONG ClientBuildNumber;
|
|
|
|
USHORT ClientProductId;
|
|
|
|
ULONG ClientHardwareId;
|
|
|
|
USHORT ClientProtocolType;
|
|
|
|
PWTS_CLIENT_DISPLAY ClientDisplay;
|
|
|
|
PWTS_CLIENT_ADDRESS ClientAddress;
|
|
|
|
WTS_CONNECTSTATE_CLASS ConnectState;
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
pBuffer = NULL;
|
|
|
|
bytesReturned = 0;
|
|
|
|
|
2014-03-18 00:39:35 +04:00
|
|
|
sessionId = pSessionInfo[index].SessionId;
|
|
|
|
|
|
|
|
printf("[%d] SessionId: %d State: %d\n", (int) index,
|
|
|
|
(int) pSessionInfo[index].SessionId,
|
|
|
|
(int) pSessionInfo[index].State);
|
|
|
|
|
|
|
|
/* WTSUserName */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSUserName, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSUserName failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Username = (char*) pBuffer;
|
|
|
|
printf("\tWTSUserName: %s\n", Username);
|
|
|
|
|
|
|
|
/* WTSDomainName */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSDomainName, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSDomainName failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Domain = (char*) pBuffer;
|
|
|
|
printf("\tWTSDomainName: %s\n", Domain);
|
|
|
|
|
|
|
|
/* WTSConnectState */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSConnectState, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSConnectState failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectState = *((WTS_CONNECTSTATE_CLASS*) pBuffer);
|
|
|
|
printf("\tWTSConnectState: %d\n", (int) ConnectState);
|
|
|
|
|
|
|
|
/* WTSClientBuildNumber */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSClientBuildNumber, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSClientBuildNumber failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientBuildNumber = *((ULONG*) pBuffer);
|
|
|
|
printf("\tWTSClientBuildNumber: %d\n", (int) ClientBuildNumber);
|
|
|
|
|
|
|
|
/* WTSClientName */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSClientName, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSClientName failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientName = (char*) pBuffer;
|
|
|
|
printf("\tWTSClientName: %s\n", ClientName);
|
|
|
|
|
|
|
|
/* WTSClientProductId */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSClientProductId, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSClientProductId failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientProductId = *((USHORT*) pBuffer);
|
|
|
|
printf("\tWTSClientProductId: %d\n", (int) ClientProductId);
|
|
|
|
|
|
|
|
/* WTSClientHardwareId */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSClientHardwareId, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSClientHardwareId failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientHardwareId = *((ULONG*) pBuffer);
|
|
|
|
printf("\tWTSClientHardwareId: %d\n", (int) ClientHardwareId);
|
|
|
|
|
|
|
|
/* WTSClientAddress */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSClientAddress, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSClientAddress failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientAddress = (PWTS_CLIENT_ADDRESS) pBuffer;
|
|
|
|
printf("\tWTSClientAddress: AddressFamily: %d\n",
|
|
|
|
(int) ClientAddress->AddressFamily);
|
|
|
|
|
|
|
|
/* WTSClientDisplay */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSClientDisplay, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSClientDisplay failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientDisplay = (PWTS_CLIENT_DISPLAY) pBuffer;
|
|
|
|
printf("\tWTSClientDisplay: HorizontalResolution: %d VerticalResolution: %d ColorDepth: %d\n",
|
|
|
|
(int) ClientDisplay->HorizontalResolution, (int) ClientDisplay->VerticalResolution,
|
|
|
|
(int) ClientDisplay->ColorDepth);
|
|
|
|
|
|
|
|
/* WTSClientProtocolType */
|
|
|
|
|
2014-05-22 21:50:01 +04:00
|
|
|
bSuccess = WTSQuerySessionInformationA(hServer, sessionId, WTSClientProtocolType, &pBuffer, &bytesReturned);
|
2014-03-18 00:39:35 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
|
|
|
printf("WTSQuerySessionInformation WTSClientProtocolType failed: %d\n", (int) GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientProtocolType = *((USHORT*) pBuffer);
|
|
|
|
printf("\tWTSClientProtocolType: %d\n", (int) ClientProtocolType);
|
|
|
|
}
|
|
|
|
|
|
|
|
WTSFreeMemory(pSessionInfo);
|
|
|
|
|
2014-03-01 09:32:23 +04:00
|
|
|
return 0;
|
|
|
|
}
|