From cc24472193ab1257e724712dccbc91bab228a1e7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 21 Feb 2020 15:51:51 -0800 Subject: [PATCH] Add a check for a screen lock due to RDP --- mist/mist.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/mist/mist.cpp b/mist/mist.cpp index 1140a79..e0d5c95 100644 --- a/mist/mist.cpp +++ b/mist/mist.cpp @@ -6,12 +6,14 @@ #include #include #include +#include #pragma comment(lib, "miniupnpc.lib") #pragma comment(lib, "libnatpmp.lib") #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "iphlpapi.lib") #pragma comment(lib, "wininet.lib") +#pragma comment(lib, "wtsapi32.lib") #define MINIUPNP_STATICLIB #include @@ -261,6 +263,41 @@ bool IsGameStreamEnabled() } } +bool IsConsoleSessionActive() +{ + PWTS_SESSION_INFO_1 sessionInfo; + DWORD sessionCount; + DWORD level; + bool ret; + DWORD activeSessionId = WTSGetActiveConsoleSessionId(); + + if (activeSessionId == 0xFFFFFFFF) { + fprintf(LOG_OUT, "No active console session detected\n"); + return false; + } + + level = 1; + if (!WTSEnumerateSessionsEx(WTS_CURRENT_SERVER_HANDLE, &level, 0, &sessionInfo, &sessionCount)) { + fprintf(LOG_OUT, "WTSEnumerateSessionsEx() failed: %d\n", GetLastError()); + return false; + } + + ret = false; + for (int i = 0; i < sessionCount; i++) + { + if (sessionInfo[i].SessionId == activeSessionId) { + if (sessionInfo[i].pUserName != nullptr) { + fprintf(LOG_OUT, "Session %d has active user\n", sessionInfo[i].SessionId); + ret = true; + break; + } + } + } + + WTSFreeMemoryExW(WTSTypeSessionInfoLevel1, sessionInfo, sessionCount); + return ret; +} + bool IsZeroTierInstalled() { DWORD error; @@ -986,6 +1023,13 @@ int main(int argc, char* argv[]) return -1; } + if (!IsConsoleSessionActive()) { + DisplayMessage("The system display is currently locked. You must sign in to your PC again to use GameStream.\n\n" + "This is most often due to Microsoft Remote Desktop locking the screen. Use an alternate GameStream-compatible remote desktop solution like Chrome Remote Desktop or TeamViewer to unlock the PC and prevent this error in the future.", + "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting"); + return -1; + } + fprintf(CONSOLE_OUT, "Checking for anti-virus and firewall software...\n"); char wmicBuf[8192];