1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <winpr/crt.h>
#include <winpr/error.h>
#include <winpr/wtsapi.h>
#include <winpr/environment.h>
int TestWtsApiSessionNotification(int argc, char* argv[])
{
HWND hWnd = NULL;
BOOL bSuccess = 0;
DWORD dwFlags = 0;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
#ifndef _WIN32
if (!GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0))
{
printf("%s: No RDS environment detected, skipping test\n", __func__);
return 0;
}
#else
/* We create a message-only window and use the predefined class name "STATIC" for simplicity */
hWnd = CreateWindowA("STATIC", "TestWtsApiSessionNotification", 0, 0, 0, 0, 0, HWND_MESSAGE,
NULL, NULL, NULL);
if (!hWnd)
{
printf("%s: error creating message-only window: %" PRIu32 "\n", __func__, GetLastError());
return -1;
}
#endif
dwFlags = NOTIFY_FOR_ALL_SESSIONS;
bSuccess = WTSRegisterSessionNotification(hWnd, dwFlags);
if (!bSuccess)
{
printf("%s: WTSRegisterSessionNotification failed: %" PRIu32 "\n", __func__,
GetLastError());
return -1;
}
bSuccess = WTSUnRegisterSessionNotification(hWnd);
#ifdef _WIN32
if (hWnd)
{
DestroyWindow(hWnd);
hWnd = NULL;
}
#endif
if (!bSuccess)
{
printf("%s: WTSUnRegisterSessionNotification failed: %" PRIu32 "\n", __func__,
GetLastError());
return -1;
}
return 0;
}
|