3 #include <winpr/error.h>
4 #include <winpr/wtsapi.h>
5 #include <winpr/environment.h>
7 int TestWtsApiEnumerateSessions(
int argc,
char* argv[])
11 HANDLE hServer = NULL;
18 if (!GetEnvironmentVariableA(
"WTSAPI_LIBRARY", NULL, 0))
20 printf(
"%s: No RDS environment detected, skipping test\n", __func__);
25 hServer = WTS_CURRENT_SERVER_HANDLE;
30 bSuccess = WTSEnumerateSessionsA(hServer, 0, 1, &pSessionInfo, &count);
34 printf(
"WTSEnumerateSessions failed: %" PRIu32
"\n", GetLastError());
38 printf(
"WTSEnumerateSessions count: %" PRIu32
"\n", count);
40 for (DWORD index = 0; index < count; index++)
42 printf(
"[%" PRIu32
"] SessionId: %" PRIu32
" WinstationName: '%s' State: %s (%u)\n", index,
43 pSessionInfo[index].SessionId, pSessionInfo[index].pWinStationName,
44 WTSSessionStateToString(pSessionInfo[index].State), pSessionInfo[index].State);
47 WTSFreeMemory(pSessionInfo);