| 1 |
|
| 2 |
#include <winpr/crt.h> |
| 3 |
#include <winpr/error.h> |
| 4 |
#include <winpr/wtsapi.h> |
| 5 |
#include <winpr/environment.h> |
| 6 |
|
| 7 |
int TestWtsApiEnumerateProcesses(int argc, char* argv[]) |
| 8 |
{ |
| 9 |
DWORD count = 0; |
| 10 |
BOOL bSuccess = 0; |
| 11 |
HANDLE hServer = nullptr; |
| 12 |
PWTS_PROCESS_INFOA pProcessInfo = nullptr; |
| 13 |
|
| 14 |
WINPR_UNUSED(argc); |
| 15 |
WINPR_UNUSED(argv); |
| 16 |
|
| 17 |
#ifndef _WIN32 |
| 18 |
if (!GetEnvironmentVariableA("WTSAPI_LIBRARY", nullptr, 0)) |
| 19 |
{ |
| 20 |
printf("%s: No RDS environment detected, skipping test\n", __func__); |
| 21 |
return 0; |
| 22 |
} |
| 23 |
#endif |
| 24 |
|
| 25 |
hServer = WTS_CURRENT_SERVER_HANDLE; |
| 26 |
|
| 27 |
count = 0; |
| 28 |
pProcessInfo = nullptr; |
| 29 |
|
| 30 |
bSuccess = WTSEnumerateProcessesA(hServer, 0, 1, &pProcessInfo, &count); |
| 31 |
|
| 32 |
if (!bSuccess) |
| 33 |
{ |
| 34 |
printf("WTSEnumerateProcesses failed: %" PRIu32 "\n", GetLastError()); |
| 35 |
return -1; |
| 36 |
} |
| 37 |
|
| 38 |
int rc = 0; |
| 39 |
{ |
| 40 |
printf("WTSEnumerateProcesses enumerated %"PRIu32" process:\n", count); |
| 41 |
for (DWORD i = 0; i < count; i++) |
| 42 |
{ |
| 43 |
const WTS_PROCESS_INFOA* cur = &pProcessInfo[i]; |
| 44 |
if (!cur->pProcessName) |
| 45 |
rc = -1; |
| 46 |
printf("\t[%" PRIu32 "]: %s (%" PRIu32 ")\n", i, cur->pProcessName, cur->ProcessId); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
WTSFreeMemory(pProcessInfo); |
| 51 |
|
| 52 |
return rc; |
| 53 |
} |