-
-
Notifications
You must be signed in to change notification settings - Fork 379
Support Always Run As Administrator #3573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jack251970
wants to merge
116
commits into
dev
Choose a base branch
from
administrator_mode
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 109 commits
Commits
Show all changes
116 commits
Select commit
Hold shift + click to select a range
7549bba
Add administrator mode check
Jack251970 369ed86
Add administrator text in tray icon
Jack251970 10d379f
Support running application under non-admin mode & Show UAC dialogs w…
Jack251970 484f91c
Improve UAC dialog
Jack251970 7611b00
Add new restart api
Jack251970 d29a5d4
Add setting model
Jack251970 40cf413
Add admin support for auto startup
Jack251970 fe70a72
Add admin mode configuration in general page
Jack251970 0edd626
Remove useless semicolon
Jack251970 91f7a4f
Remove useless semicolon
Jack251970 902c8f4
Check value changed
Jack251970 c5c24ac
Check run level
Jack251970 1073061
Remove old before creating new one
Jack251970 e9c40e4
Revert "Add new restart api"
Jack251970 365ba6a
Code quality
Jack251970 eae4a95
Use readonly bool variable
Jack251970 52c36ff
Only restart from non-admin to admin & Fix restart as administrator i…
Jack251970 35f4fd5
Fix restart as administrator issue
Jack251970 eacccf9
Add code comments & Use local function
Jack251970 d6462f4
Move restart function to app class
Jack251970 479b49d
Throw UnauthorizedAccessException when encountering admin issue
Jack251970 c3ec002
Show message box to ask users to restart as administrator when encoun…
Jack251970 80c0288
Throw exception when editing highest run level task
Jack251970 1b80290
Do not show noticification when run level is correct
Jack251970 ca6f077
Merge branch 'dev' into administrator_mode
Jack251970 ba1ada7
Continue to restart app as administrator if app is run as administrat…
Jack251970 b2edea4
Improve code quality
Jack251970 de26abe
Use api functions instead
Jack251970 23f2489
Force admin restart and fix build issue
Jack251970 2c1f161
Merge branch 'dev' into administrator_mode
Jack251970 1a8334f
Add RunAsDesktopUser helper method
Jack251970 e391c98
Code quality
Jack251970 100c21a
Add new api to run process as desktop user
Jack251970 fc53efd
Use new api function to open application
Jack251970 d77993e
Use new api function to start shell process
Jack251970 4cf6636
Fix handle close issue
Jack251970 f1f7309
Add working directory check & Add try-catch
Jack251970 e8c03c6
Update documents
Jack251970 ea9ede2
Fix deelevate process running issue
Jack251970 d13901b
Update work directory correctly
Jack251970 f9b2be1
Let work directory can be empty
Jack251970 30deb6d
Fix argument sequence issue
Jack251970 fb4735f
Fix program deelevate open issue
Jack251970 b15cece
Fix absolute exe file path issue
Jack251970 255ca5a
Improve code quality
Jack251970 433e0fd
Improve uac dialog path
Jack251970 21e8d92
Add show uac dialog api function
Jack251970 0d1358f
Add return value for start process api function
Jack251970 a775323
Improve uac dialog api function
Jack251970 a3212af
Dynamically find wt.exe
Jack251970 8b8fcd8
Add IsAdmin
Jack251970 94f0bb9
Handle command running with administrator mode correctly
Jack251970 6842fca
Replace IntPtr.Zero with Handle or HWND
Jack251970 9c6c015
Reflect user intent
Jack251970 8cfaeea
Return value of RunAsDesktopUser
Jack251970 61717dc
Ensure SetImageAsync exceptions are handled
Jack251970 393d106
Fix command line pass issue
Jack251970 2df7a61
Add command project
Jack251970 13b5012
Add command executer path
Jack251970 b8a697c
Fix running issue
Jack251970 a0ebe29
Improve api function
Jack251970 3ed8af8
Use new api for program plugin
Jack251970 5551bdf
Remove uac dialog api function
Jack251970 2c0210c
Revert unnecessary changes in solution file
Jack251970 898dbb8
Use new api for uwp package opening
Jack251970 4ebfb3c
Add api function
Jack251970 a2be6e0
Use new api for shell plugin
Jack251970 50a8e88
Use double quotes to fix possible issue
Jack251970 d56f0a0
Improve process information handler
Jack251970 dae6f5d
Use WinExe to avoid console ui
Jack251970 6109504
Add solution assembly information
Jack251970 8287b33
Fix typo
Jack251970 be2c59e
Call Win32Helper.IsAdministrator() directly
Jack251970 d1b4c3c
Merge branch 'administrator_mode' of https://github.com/Flow-Launcher…
Jack251970 5ddf705
Fix typo
Jack251970 6843fe0
Fix parameter issue
Jack251970 680419f
Code quality
Jack251970 02de9d6
Merge branch 'dev' into administrator_mode
Jack251970 dd0899f
Check always running as administrator
Jack251970 1fabe8d
Improve string resource
Jack251970 def02b3
Improve xml documents
Jack251970 9d480fc
Quote the executable path to survive spaces & Improve code quality
Jack251970 f2d3ba7
Combine restart functions to one function
Jack251970 3a92102
Add new api RestartAppAsAdmin
Jack251970 d363cad
Improve code quality
Jack251970 0602143
Change target framework
Jack251970 7930d57
Add publish file
Jack251970 8dd9b9c
Publish command project
Jack251970 11c0eb3
Fix command project publish issue
Jack251970 7fd3a4a
Merge branch 'dev' into administrator_mode
Jack251970 a34e404
Change target framework
Jack251970 ad6d598
Change publish sequence
Jack251970 764b524
Use exe console type & Add flag support for helper method
Jack251970 2f3b973
Do not publish command project
Jack251970 935101c
Change command project output path
Jack251970 8c81808
Change default value
Jack251970 e1242ee
Check Process.Start usage
Jack251970 a76ade8
Merge branch 'dev' into administrator_mode
Jack251970 e5316a0
Check Process.Start usage
Jack251970 b6b45d4
Improve code quality
Jack251970 4df7264
Improve documents
Jack251970 1dfec7f
Merge branch 'dev' into administrator_mode
Jack251970 39de484
Merge branch 'administrator_mode' of https://github.com/Flow-Launcher…
Jack251970 44b25b4
Prefer injected Context over static Main.Context
Jack251970 d1daf51
Merge branch 'dev' into administrator_mode
Jack251970 478ba29
Change target framework to remove dll files
Jack251970 9119998
Build command project after main project
Jack251970 3493446
Support createNoWindow for start process api
Jack251970 7ea76b8
Support administrator handling for ShellRun api function
Jack251970 721bb98
Handle create no window parameter in command exe
Jack251970 81667d0
Fix ui issue
Jack251970 10567fd
Merge branch 'dev' into administrator_mode
Jack251970 4862a2d
Check if the application is running as administrator ealier
Jack251970 4416efe
Revert "Check if the application is running as administrator ealier"
Jack251970 71af5ef
Check if the application is running as administrator ealier
Jack251970 48ed897
Merge branch 'dev' into administrator_mode
Jack251970 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>Flow.Launcher.Command</RootNamespace> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<ApplicationIcon>app.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>portable</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\Output\Debug\Command\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<UseVSHostingProcess>true</UseVSHostingProcess> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>..\Output\Release\Command\</OutputPath> | ||
<DefineConstants>TRACE;RELEASE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="app.ico" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\SolutionAssemblyInfo.cs" Link="Properties\SolutionAssemblyInfo.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Flow.Launcher.Command; | ||
|
||
internal static class Program | ||
{ | ||
[STAThread] | ||
private static int Main(string[] args) | ||
{ | ||
if (args.Length == 0) return -1; | ||
|
||
// Start process with arguments | ||
// Usage: Flow.Launcher.Command -StartProcess -FileName <file> -WorkingDirectory <directory> -Arguments <args> -UseShellExecute <true|false> -Verb <verb> | ||
if (args[0] == @"-StartProcess") | ||
{ | ||
var fileName = string.Empty; | ||
var workingDirectory = Environment.CurrentDirectory; | ||
var argumentList = new List<string>(); | ||
var useShellExecute = true; | ||
var verb = string.Empty; | ||
var isArguments = false; | ||
|
||
for (int i = 1; i < args.Length; i++) | ||
{ | ||
switch (args[i]) | ||
{ | ||
case "-FileName": | ||
if (i + 1 < args.Length) | ||
fileName = args[++i]; | ||
isArguments = false; | ||
break; | ||
|
||
case "-WorkingDirectory": | ||
if (i + 1 < args.Length) | ||
workingDirectory = args[++i]; | ||
isArguments = false; | ||
break; | ||
|
||
case "-Arguments": | ||
if (i + 1 < args.Length) | ||
argumentList.Add(args[++i]); | ||
isArguments = true; | ||
break; | ||
|
||
case "-UseShellExecute": | ||
if (i + 1 < args.Length && bool.TryParse(args[++i], out bool useShell)) | ||
useShellExecute = useShell; | ||
isArguments = false; | ||
break; | ||
|
||
case "-Verb": | ||
if (i + 1 < args.Length) | ||
verb = args[++i]; | ||
isArguments = false; | ||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break; | ||
|
||
default: | ||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (isArguments) | ||
argumentList.Add(args[i]); | ||
else | ||
Console.WriteLine($"Unknown parameter: {args[i]}"); | ||
break; | ||
} | ||
} | ||
|
||
if (string.IsNullOrEmpty(fileName)) | ||
{ | ||
Console.WriteLine("Error: -FileName is required."); | ||
return -2; | ||
} | ||
|
||
try | ||
{ | ||
ProcessStartInfo info; | ||
if (argumentList.Count == 0) | ||
{ | ||
info = new ProcessStartInfo | ||
{ | ||
FileName = fileName, | ||
WorkingDirectory = workingDirectory, | ||
UseShellExecute = useShellExecute, | ||
Verb = verb | ||
}; | ||
} | ||
else if (argumentList.Count == 1) | ||
{ | ||
info = new ProcessStartInfo | ||
{ | ||
FileName = fileName, | ||
WorkingDirectory = workingDirectory, | ||
Arguments = argumentList[0], | ||
UseShellExecute = useShellExecute, | ||
Verb = verb | ||
}; | ||
} | ||
else | ||
{ | ||
info = new ProcessStartInfo | ||
{ | ||
FileName = fileName, | ||
WorkingDirectory = workingDirectory, | ||
UseShellExecute = useShellExecute, | ||
Verb = verb | ||
}; | ||
foreach (var arg in argumentList) | ||
{ | ||
info.ArgumentList.Add(arg); | ||
} | ||
} | ||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Process.Start(info)?.Dispose(); | ||
Console.WriteLine("Success."); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Error: {ex.Message}"); | ||
return -3; | ||
} | ||
} | ||
|
||
return -4; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Flow.Launcher.Command/Properties/PublishProfiles/Net7.0-SelfContained.pubxml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework> | ||
<PublishDir>..\Output\Release\</PublishDir> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
<SelfContained>true</SelfContained> | ||
<PublishSingleFile>False</PublishSingleFile> | ||
<PublishReadyToRun>False</PublishReadyToRun> | ||
<PublishTrimmed>False</PublishTrimmed> | ||
</PropertyGroup> | ||
</Project> |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.