From 764b524ea4f495e80be3a22e6f2add7e886d02f4 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 14 Jun 2025 15:08:48 +0800 Subject: [PATCH] Use exe console type & Add flag support for helper method --- Flow.Launcher.Command/Flow.Launcher.Command.csproj | 2 +- Flow.Launcher.Infrastructure/Win32Helper.cs | 11 +++++++---- Flow.Launcher/PublicAPIInstance.cs | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Command/Flow.Launcher.Command.csproj b/Flow.Launcher.Command/Flow.Launcher.Command.csproj index c28b1897a..3478a6a5e 100644 --- a/Flow.Launcher.Command/Flow.Launcher.Command.csproj +++ b/Flow.Launcher.Command/Flow.Launcher.Command.csproj @@ -1,7 +1,7 @@  - WinExe + Exe net7.0-windows10.0.19041.0 enable enable diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 4fe995e8a..d24db1718 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -808,7 +808,7 @@ namespace Flow.Launcher.Infrastructure /// Inspired by /// Document: /// - public static unsafe bool RunAsDesktopUser(string app, string currentDir, string cmdLine, out string errorInfo) + public static unsafe bool RunAsDesktopUser(string app, string currentDir, string cmdLine, bool loadProfile, bool createNoWindow, out string errorInfo) { STARTUPINFOW si = new(); PROCESS_INFORMATION pi = new(); @@ -916,11 +916,14 @@ retry: fixed (char* cmdLinePtr = $"- {cmdLine}") fixed (char* currentDirPtr = currentDir) { - if (!PInvoke.CreateProcessWithToken(hPrimaryToken, - 0, + if (!PInvoke.CreateProcessWithToken( + hPrimaryToken, + // If you need to access content in HKEY_CURRENT_USER, please set loadProfile to true + loadProfile ? CREATE_PROCESS_LOGON_FLAGS.LOGON_WITH_PROFILE : 0, appPtr, cmdLinePtr, - 0, + // If you do not want to create a window for console app, please set createNoWindow to true + createNoWindow ? PROCESS_CREATION_FLAGS.CREATE_NO_WINDOW : 0, null, currentDirPtr, &si, diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index df9964cac..9f32ffadc 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -595,6 +595,8 @@ namespace Flow.Launcher Constant.CommandExecutablePath, Environment.CurrentDirectory, $"-StartProcess -FileName {AddDoubleQuotes(filePath)} -WorkingDirectory {AddDoubleQuotes(workingDirectory)} -Arguments {AddDoubleQuotes(arguments)} -UseShellExecute {useShellExecute} -Verb {AddDoubleQuotes(verb)}", + false, + true, // Do not show the command window out var errorInfo); if (!string.IsNullOrEmpty(errorInfo)) {