Skip to content

Commit 764b524

Browse files
committed
Use exe console type & Add flag support for helper method
1 parent ad6d598 commit 764b524

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Flow.Launcher.Command/Flow.Launcher.Command.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>WinExe</OutputType>
4+
<OutputType>Exe</OutputType>
55
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ public static bool IsAdministrator()
808808
/// Inspired by <see href="https://github.com/jay/RunAsDesktopUser">
809809
/// Document: <see href="https://learn.microsoft.com/en-us/archive/blogs/aaron_margosis/faq-how-do-i-start-a-program-as-the-desktop-user-from-an-elevated-app">
810810
/// </summary>
811-
public static unsafe bool RunAsDesktopUser(string app, string currentDir, string cmdLine, out string errorInfo)
811+
public static unsafe bool RunAsDesktopUser(string app, string currentDir, string cmdLine, bool loadProfile, bool createNoWindow, out string errorInfo)
812812
{
813813
STARTUPINFOW si = new();
814814
PROCESS_INFORMATION pi = new();
@@ -916,11 +916,14 @@ public static unsafe bool RunAsDesktopUser(string app, string currentDir, string
916916
fixed (char* cmdLinePtr = $"- {cmdLine}")
917917
fixed (char* currentDirPtr = currentDir)
918918
{
919-
if (!PInvoke.CreateProcessWithToken(hPrimaryToken,
920-
0,
919+
if (!PInvoke.CreateProcessWithToken(
920+
hPrimaryToken,
921+
// If you need to access content in HKEY_CURRENT_USER, please set loadProfile to true
922+
loadProfile ? CREATE_PROCESS_LOGON_FLAGS.LOGON_WITH_PROFILE : 0,
921923
appPtr,
922924
cmdLinePtr,
923-
0,
925+
// If you do not want to create a window for console app, please set createNoWindow to true
926+
createNoWindow ? PROCESS_CREATION_FLAGS.CREATE_NO_WINDOW : 0,
924927
null,
925928
currentDirPtr,
926929
&si,

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ public bool StartProcess(string filePath, string workingDirectory = "", string a
595595
Constant.CommandExecutablePath,
596596
Environment.CurrentDirectory,
597597
$"-StartProcess -FileName {AddDoubleQuotes(filePath)} -WorkingDirectory {AddDoubleQuotes(workingDirectory)} -Arguments {AddDoubleQuotes(arguments)} -UseShellExecute {useShellExecute} -Verb {AddDoubleQuotes(verb)}",
598+
false,
599+
true, // Do not show the command window
598600
out var errorInfo);
599601
if (!string.IsNullOrEmpty(errorInfo))
600602
{

0 commit comments

Comments
 (0)