From c5c43d99f35c72567e5b84238c8ce06bd984d14b Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 16 Jan 2021 07:41:28 -0500 Subject: [PATCH] [host] windows: allow capture of login screen WTSGetActiveConsoleSessionId will return a session even if it's not logged in, unlike our old GetInteractiveSessionID function. Launching looking glass on such a console session will allow the login screen to be captured. Note that WTSGetActiveConsoleSessionId() will return 0xFFFFFFFF if there are no sessions attached. --- host/platform/Windows/src/service.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/host/platform/Windows/src/service.c b/host/platform/Windows/src/service.c index 80e1241d..1d5b85af 100644 --- a/host/platform/Windows/src/service.c +++ b/host/platform/Windows/src/service.c @@ -247,29 +247,6 @@ err_proc: return NULL; } -DWORD GetInteractiveSessionID(void) -{ - PWTS_SESSION_INFO pSessionInfo; - DWORD count; - DWORD ret = 0; - - if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, - &count)) - return 0; - - for(DWORD i = 0; i < count; ++i) - { - if (pSessionInfo[i].State == WTSActive) - { - ret = pSessionInfo[i].SessionId; - break; - } - } - - WTSFreeMemory(pSessionInfo); - return ret; -} - void Launch(void) { if (service.process) @@ -301,7 +278,7 @@ void Launch(void) if (!enablePriv(SE_TCB_NAME)) goto fail_token; - targetSessionID = GetInteractiveSessionID(); + targetSessionID = WTSGetActiveConsoleSessionId(); if (origSessionID != targetSessionID) { if (!SetTokenInformation(hToken, TokenSessionId, @@ -669,7 +646,8 @@ VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR *lpszArgv) { ULONGLONG launchTime; - if (GetInteractiveSessionID() != 0) + DWORD interactiveSession = WTSGetActiveConsoleSessionId(); + if (interactiveSession != 0 && interactiveSession != 0xFFFFFFFF) { Launch(); launchTime = GetTickCount64();