diff --git a/src/gsudo/Helpers/ServiceHelper.cs b/src/gsudo/Helpers/ServiceHelper.cs index c95eed9..d18feab 100644 --- a/src/gsudo/Helpers/ServiceHelper.cs +++ b/src/gsudo/Helpers/ServiceHelper.cs @@ -178,19 +178,19 @@ internal static SafeProcessHandle StartService(int? allowedPid, TimeSpan? cacheD if (SecurityHelper.IsMemberOfLocalAdmins() && InputArguments.GetIntegrityLevel() >= IntegrityLevel.High) { // UAC Popup doesnt always have focus, so we try to bring it to the front. - new Thread(UACWindowFocusHelper.FocusUacWindow).Start(); - + UACWindowFocusHelper.StartBackgroundThreadToFocusUacWindow(); ret = ProcessFactory.StartElevatedDetached(ownExe, commandLine, !InputArguments.Debug).GetSafeProcessHandle(); } else + { ret = ProcessFactory.StartDetached(ownExe, commandLine, null, !InputArguments.Debug).GetSafeProcessHandle(); + } } } else { // UAC Popup doesnt always have focus, so we try to bring it to the front. - new Thread(UACWindowFocusHelper.FocusUacWindow).Start(); - + UACWindowFocusHelper.StartBackgroundThreadToFocusUacWindow(); ret = ProcessFactory.StartElevatedDetached(ownExe, commandLine, !InputArguments.Debug).GetSafeProcessHandle(); } diff --git a/src/gsudo/Helpers/UACWindowFocusHelper.cs b/src/gsudo/Helpers/UACWindowFocusHelper.cs index f2a9851..d4b22e1 100644 --- a/src/gsudo/Helpers/UACWindowFocusHelper.cs +++ b/src/gsudo/Helpers/UACWindowFocusHelper.cs @@ -1,6 +1,7 @@ using gsudo.Native; using System; using System.Runtime.InteropServices; +using System.Threading; namespace gsudo.Helpers { @@ -9,6 +10,13 @@ internal class UACWindowFocusHelper [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); + internal static void StartBackgroundThreadToFocusUacWindow() + { + var focusThread = new Thread(UACWindowFocusHelper.FocusUacWindow); + focusThread.IsBackground = true; + focusThread.Start(); + } + internal static void FocusUacWindow() { try