2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/error.h>
|
|
|
|
#include <winpr/wtsapi.h>
|
2016-05-30 18:54:59 +03:00
|
|
|
#include <winpr/environment.h>
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
int TestWtsApiEnumerateSessions(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
DWORD index;
|
|
|
|
DWORD count;
|
|
|
|
BOOL bSuccess;
|
|
|
|
HANDLE hServer;
|
2016-05-30 18:54:59 +03:00
|
|
|
PWTS_SESSION_INFOA pSessionInfo;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
if (!GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0))
|
|
|
|
{
|
|
|
|
printf("%s: No RDS environment detected, skipping test\n", __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
hServer = WTS_CURRENT_SERVER_HANDLE;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
pSessionInfo = NULL;
|
|
|
|
|
2016-05-30 18:54:59 +03:00
|
|
|
bSuccess = WTSEnumerateSessionsA(hServer, 0, 1, &pSessionInfo, &count);
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("WTSEnumerateSessions failed: %"PRIu32"\n", GetLastError());
|
2014-04-09 18:01:58 +04:00
|
|
|
return 0;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("WTSEnumerateSessions count: %"PRIu32"\n", count);
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
printf("[%"PRIu32"] SessionId: %"PRIu32" WinstationName: '%s' State: %s (%u)\n", index,
|
2016-05-30 18:54:59 +03:00
|
|
|
pSessionInfo[index].SessionId,
|
|
|
|
pSessionInfo[index].pWinStationName,
|
|
|
|
WTSSessionStateToString(pSessionInfo[index].State),
|
|
|
|
pSessionInfo[index].State);
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WTSFreeMemory(pSessionInfo);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|