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;
|
|
|
|
|
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 */
|
|
|
|
hWnd = CreateWindowA("STATIC", "TestWtsApiSessionNotification", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
|
|
|
|
if (!hWnd)
|
|
|
|
{
|
|
|
|
printf("%s: error creating message-only window: %u\n", __FUNCTION__, GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-01 09:32:23 +04:00
|
|
|
dwFlags = NOTIFY_FOR_ALL_SESSIONS;
|
|
|
|
|
|
|
|
bSuccess = WTSRegisterSessionNotification(hWnd, dwFlags);
|
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
2016-05-30 18:54:59 +03:00
|
|
|
printf("%s: WTSRegisterSessionNotification failed: %u\n", __FUNCTION__, GetLastError());
|
|
|
|
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)
|
|
|
|
{
|
2016-05-30 18:54:59 +03:00
|
|
|
printf("%s: WTSUnRegisterSessionNotification failed: %u\n", __FUNCTION__, GetLastError());
|
|
|
|
return -1;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|