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 TestWtsApiSessionNotification(int argc, char* argv[])
|
|
|
|
{
|
2016-05-30 18:54:59 +03:00
|
|
|
HWND hWnd = NULL;
|
2014-03-01 09:32:23 +04:00
|
|
|
BOOL bSuccess;
|
|
|
|
DWORD dwFlags;
|
|
|
|
|
2021-07-29 11:18:52 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
|
|
|
|
2016-05-30 18:54:59 +03:00
|
|
|
#ifndef _WIN32
|
|
|
|
if (!GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0))
|
|
|
|
{
|
|
|
|
printf("%s: No RDS environment detected, skipping test\n", __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* We create a message-only window and use the predefined class name "STATIC" for simplicity */
|
2019-11-06 17:24:51 +03:00
|
|
|
hWnd = CreateWindowA("STATIC", "TestWtsApiSessionNotification", 0, 0, 0, 0, 0, HWND_MESSAGE,
|
|
|
|
NULL, NULL, NULL);
|
2016-05-30 18:54:59 +03:00
|
|
|
if (!hWnd)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("%s: error creating message-only window: %" PRIu32 "\n", __FUNCTION__,
|
|
|
|
GetLastError());
|
2016-05-30 18:54:59 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-01 09:32:23 +04:00
|
|
|
dwFlags = NOTIFY_FOR_ALL_SESSIONS;
|
|
|
|
|
|
|
|
bSuccess = WTSRegisterSessionNotification(hWnd, dwFlags);
|
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("%s: WTSRegisterSessionNotification failed: %" PRIu32 "\n", __FUNCTION__,
|
|
|
|
GetLastError());
|
2016-05-30 18:54:59 +03:00
|
|
|
return -1;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bSuccess = WTSUnRegisterSessionNotification(hWnd);
|
|
|
|
|
2016-05-30 18:54:59 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (hWnd)
|
|
|
|
{
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
hWnd = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-01 09:32:23 +04:00
|
|
|
if (!bSuccess)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("%s: WTSUnRegisterSessionNotification failed: %" PRIu32 "\n", __FUNCTION__,
|
|
|
|
GetLastError());
|
2016-05-30 18:54:59 +03:00
|
|
|
return -1;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|