From 38be84df77e520b448187082c9891b1cc6c532dd Mon Sep 17 00:00:00 2001 From: Daniel Hompanera Date: Thu, 14 Jul 2022 13:39:39 +0200 Subject: [PATCH] Adjustments to POpen's windows part to not hide HelixMFA window and to wait until closed --- Common/POpen.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Common/POpen.cpp b/Common/POpen.cpp index 5a4b58c..c5620fe 100644 --- a/Common/POpen.cpp +++ b/Common/POpen.cpp @@ -53,7 +53,7 @@ POpen::POpen(const std::string& cmd) : m_Command(cmd) siStartInfo.hStdOutput = m_ChildStd_OUT_Wr; siStartInfo.hStdInput = m_ChildStd_IN_Rd; siStartInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; - siStartInfo.wShowWindow = SW_HIDE; + siStartInfo.wShowWindow = SW_SHOW; const size_t kCommandSize = 32768; static wchar_t widePath[kCommandSize]; @@ -85,7 +85,7 @@ POpen::POpen(const std::string& cmd) : m_Command(cmd) // before we can be confident that the process is running ok. DWORD msWait = 10000; // Wait at most 10 seconds DWORD exitCode; - DWORD waitRes = WaitForInputIdle(m_ProcInfo.hProcess, msWait); + DWORD waitRes = WaitForInputIdle(m_ProcInfo.hProcess, INFINITE); switch (waitRes) { case WAIT_TIMEOUT: @@ -100,6 +100,10 @@ POpen::POpen(const std::string& cmd) : m_Command(cmd) //WaitForSingleObject(m_ProcInfo.hProcess, msWait); //GetExitCodeProcess(m_ProcInfo.hProcess, &exitCode); } + else if (exitCode == 0) + { + break; + } else { throw PluginException(std::string("Process failed '") + cmd + "' exit code " + IntToString(exitCode)); @@ -109,6 +113,8 @@ POpen::POpen(const std::string& cmd) : m_Command(cmd) break; } + WaitForSingleObject(m_ProcInfo.hProcess, INFINITE); + if (!GetExitCodeProcess(m_ProcInfo.hProcess, &exitCode)) throw PluginException(std::string("Could not get exit code for process '") + cmd + "': " + LastErrorToMsg());