FreeRDP
TestWtsApiEnumerateProcesses.c
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 = NULL;
12  PWTS_PROCESS_INFOA pProcessInfo = NULL;
13 
14  WINPR_UNUSED(argc);
15  WINPR_UNUSED(argv);
16 
17 #ifndef _WIN32
18  if (!GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 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 = NULL;
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 #if 0
39  {
40  printf("WTSEnumerateProcesses enumerated %"PRIu32" processs:\n", count);
41  for (DWORD i = 0; i < count; i++)
42  printf("\t[%"PRIu32"]: %s (%"PRIu32")\n", i, pProcessInfo[i].pProcessName, pProcessInfo[i].ProcessId);
43  }
44 #endif
45 
46  WTSFreeMemory(pProcessInfo);
47 
48  return 0;
49 }