From 8ef2e7edbc14f6f0543b8de2661112b540c50ae9 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Thu, 2 Aug 2018 18:04:32 +0100 Subject: [PATCH] #6383 Refactor set startup info to a function --- src/lib/platform/MSWindowsWatchdog.cpp | 29 +++++++++++++------------- src/lib/platform/MSWindowsWatchdog.h | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp index ad63c93c..c9609594 100644 --- a/src/lib/platform/MSWindowsWatchdog.cpp +++ b/src/lib/platform/MSWindowsWatchdog.cpp @@ -351,19 +351,25 @@ MSWindowsWatchdog::startProcess() } } +void +MSWindowsWatchdog::setStartupInfo(STARTUPINFO& si) +{ + ZeroMemory(&si, sizeof(STARTUPINFO)); + si.cb = sizeof(STARTUPINFO); + si.lpDesktop = "winsta0\\Default"; // TODO: maybe this should be \winlogon if we have logonui.exe? + si.hStdError = m_stdOutWrite; + si.hStdOutput = m_stdOutWrite; + si.dwFlags |= STARTF_USESTDHANDLES; +} + BOOL MSWindowsWatchdog::startProcessInForeground(String& command) { // clear, as we're reusing process info struct ZeroMemory(&m_processInfo, sizeof(PROCESS_INFORMATION)); - STARTUPINFO si; - ZeroMemory(&si, sizeof(STARTUPINFO)); - si.cb = sizeof(STARTUPINFO); - si.lpDesktop = "winsta0\\Default"; // TODO: maybe this should be \winlogon if we have logonui.exe? - si.hStdError = m_stdOutWrite; - si.hStdOutput = m_stdOutWrite; - si.dwFlags |= STARTF_USESTDHANDLES; + STARTUPINFO si; + setStartupInfo(si); return CreateProcess( NULL, LPSTR(command.c_str()), NULL, NULL, @@ -376,13 +382,8 @@ MSWindowsWatchdog::startProcessAsUser(String& command, HANDLE userToken, LPSECUR // clear, as we're reusing process info struct ZeroMemory(&m_processInfo, sizeof(PROCESS_INFORMATION)); - STARTUPINFO si; - ZeroMemory(&si, sizeof(STARTUPINFO)); - si.cb = sizeof(STARTUPINFO); - si.lpDesktop = "winsta0\\Default"; // TODO: maybe this should be \winlogon if we have logonui.exe? - si.hStdError = m_stdOutWrite; - si.hStdOutput = m_stdOutWrite; - si.dwFlags |= STARTF_USESTDHANDLES; + STARTUPINFO si; + setStartupInfo(si); LPVOID environment; BOOL blockRet = CreateEnvironmentBlock(&environment, userToken, FALSE); diff --git a/src/lib/platform/MSWindowsWatchdog.h b/src/lib/platform/MSWindowsWatchdog.h index 692af3d5..f1feedb4 100644 --- a/src/lib/platform/MSWindowsWatchdog.h +++ b/src/lib/platform/MSWindowsWatchdog.h @@ -61,6 +61,7 @@ private: void sendSas(); void getActiveDesktop(LPSECURITY_ATTRIBUTES security); void testOutput(String buffer); + void setStartupInfo(STARTUPINFO& si); private: Thread* m_thread;