[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.
This commit is contained in:
Quantum 2021-01-16 07:41:28 -05:00 committed by Geoffrey McRae
parent 2738e822a4
commit c5c43d99f3

View File

@ -247,29 +247,6 @@ err_proc:
return NULL; 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) void Launch(void)
{ {
if (service.process) if (service.process)
@ -301,7 +278,7 @@ void Launch(void)
if (!enablePriv(SE_TCB_NAME)) if (!enablePriv(SE_TCB_NAME))
goto fail_token; goto fail_token;
targetSessionID = GetInteractiveSessionID(); targetSessionID = WTSGetActiveConsoleSessionId();
if (origSessionID != targetSessionID) if (origSessionID != targetSessionID)
{ {
if (!SetTokenInformation(hToken, TokenSessionId, if (!SetTokenInformation(hToken, TokenSessionId,
@ -669,7 +646,8 @@ VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR *lpszArgv)
{ {
ULONGLONG launchTime; ULONGLONG launchTime;
if (GetInteractiveSessionID() != 0) DWORD interactiveSession = WTSGetActiveConsoleSessionId();
if (interactiveSession != 0 && interactiveSession != 0xFFFFFFFF)
{ {
Launch(); Launch();
launchTime = GetTickCount64(); launchTime = GetTickCount64();