mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #663 from themike10452/dev
run as administration when holding ctrl and shift
This commit is contained in:
commit
1a7c1720d3
9 changed files with 145 additions and 11 deletions
|
|
@ -46,6 +46,7 @@
|
|||
<KeyBinding Key="Home" Modifiers="Alt" Command="{Binding SelectFirstResultCommand}"></KeyBinding>
|
||||
<KeyBinding Key="O" Modifiers="Ctrl" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
|
||||
<KeyBinding Key="H" Modifiers="Ctrl" Command="{Binding LoadHistoryCommand}"></KeyBinding>
|
||||
<KeyBinding Key="Enter" Modifiers="Ctrl+Shift" Command="{Binding OpenResultCommand}"></KeyBinding>
|
||||
<KeyBinding Key="Enter" Modifiers="Shift" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
|
||||
<KeyBinding Key="Enter" Command="{Binding OpenResultCommand}"></KeyBinding>
|
||||
<KeyBinding Key="Enter" Modifiers="Ctrl" Command="{Binding OpenResultCommand}"></KeyBinding>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Explorer.Search
|
||||
|
|
@ -127,7 +129,26 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
{
|
||||
try
|
||||
{
|
||||
if (c.SpecialKeyState.CtrlPressed)
|
||||
if (File.Exists(filePath) && c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = filePath,
|
||||
UseShellExecute = true,
|
||||
Verb = "runas",
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.Message, "Could not start " + filePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (c.SpecialKeyState.CtrlPressed)
|
||||
{
|
||||
FilesFolders.OpenContainingFolder(filePath);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,5 +53,6 @@
|
|||
<!--Dialogs-->
|
||||
<system:String x:Key="flowlauncher_plugin_program_disable_dlgtitle_success">Success</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_program_disable_dlgtitle_success_message">Successfully disabled this program from displaying in your query</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_program_run_as_administrator_not_supported_message">This app is not intended to be run as administrator</system:String>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
|
@ -33,4 +33,5 @@
|
|||
|
||||
<system:String x:Key="flowlauncher_plugin_program_plugin_name">程式</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_program_plugin_description">在 Flow Launcher 中搜尋程式</system:String>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
|
|
|||
|
|
@ -267,6 +267,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
public string Location => Package.Location;
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public bool CanRunElevated { get; set; }
|
||||
|
||||
public string LogoUri { get; set; }
|
||||
public string LogoPath { get; set; }
|
||||
|
|
@ -320,7 +321,29 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
ContextData = this,
|
||||
Action = e =>
|
||||
{
|
||||
Launch(api);
|
||||
var elevated = (
|
||||
e.SpecialKeyState.CtrlPressed &&
|
||||
e.SpecialKeyState.ShiftPressed &&
|
||||
!e.SpecialKeyState.AltPressed &&
|
||||
!e.SpecialKeyState.WinPressed
|
||||
);
|
||||
|
||||
if (elevated && CanRunElevated)
|
||||
{
|
||||
LaunchElevated();
|
||||
}
|
||||
else
|
||||
{
|
||||
Launch(api);
|
||||
|
||||
if (elevated)
|
||||
{
|
||||
var title = "Plugin: Program";
|
||||
var message = api.GetTranslation("flowlauncher_plugin_program_run_as_administrator_not_supported_message");
|
||||
api.ShowMsg(title, message, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
@ -354,6 +377,21 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
IcoPath = "Images/folder.png"
|
||||
}
|
||||
};
|
||||
|
||||
if (CanRunElevated)
|
||||
{
|
||||
contextMenus.Add(new Result
|
||||
{
|
||||
Title = api.GetTranslation("flowlauncher_plugin_program_run_as_administrator"),
|
||||
Action = _ =>
|
||||
{
|
||||
LaunchElevated();
|
||||
return true;
|
||||
},
|
||||
IcoPath = "Images/cmd.png"
|
||||
});
|
||||
}
|
||||
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
|
|
@ -377,6 +415,20 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
});
|
||||
}
|
||||
|
||||
private async void LaunchElevated()
|
||||
{
|
||||
string command = "shell:AppsFolder\\" + UniqueIdentifier;
|
||||
command = Environment.ExpandEnvironmentVariables(command.Trim());
|
||||
|
||||
var info = new ProcessStartInfo(command)
|
||||
{
|
||||
UseShellExecute = true,
|
||||
Verb = "runas",
|
||||
};
|
||||
|
||||
Main.StartProcess(Process.Start, info);
|
||||
}
|
||||
|
||||
public Application(AppxPackageHelper.IAppxManifestApplication manifestApp, UWP package)
|
||||
{
|
||||
// This is done because we cannot use the keyword 'out' along with a property
|
||||
|
|
@ -403,6 +455,28 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
LogoPath = LogoPathFromUri(LogoUri);
|
||||
|
||||
Enabled = true;
|
||||
CanRunElevated = CanApplicationRunElevated();
|
||||
}
|
||||
|
||||
private bool CanApplicationRunElevated()
|
||||
{
|
||||
if (EntryPoint == "Windows.FullTrustApplication")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var manifest = Package.Location + "\\AppxManifest.xml";
|
||||
if (File.Exists(manifest))
|
||||
{
|
||||
var file = File.ReadAllText(manifest);
|
||||
|
||||
if (file.Contains("TrustLevel=\"mediumIL\"", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal string ResourceFromPri(string packageFullName, string packageName, string rawReferenceValue)
|
||||
|
|
|
|||
|
|
@ -102,16 +102,24 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
Score = matchResult.Score,
|
||||
TitleHighlightData = matchResult.MatchData,
|
||||
ContextData = this,
|
||||
Action = _ =>
|
||||
Action = c =>
|
||||
{
|
||||
var runAsAdmin = (
|
||||
c.SpecialKeyState.CtrlPressed &&
|
||||
c.SpecialKeyState.ShiftPressed &&
|
||||
!c.SpecialKeyState.AltPressed &&
|
||||
!c.SpecialKeyState.WinPressed
|
||||
);
|
||||
|
||||
var info = new ProcessStartInfo
|
||||
{
|
||||
FileName = LnkResolvedPath ?? FullPath,
|
||||
WorkingDirectory = ParentDirectory,
|
||||
UseShellExecute = true
|
||||
UseShellExecute = true,
|
||||
Verb = runAsAdmin ? "runas" : null
|
||||
};
|
||||
|
||||
Main.StartProcess(Process.Start, info);
|
||||
Task.Run(() => Main.StartProcess(Process.Start, info));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Name": "Program",
|
||||
"Description": "Search programs in Flow.Launcher",
|
||||
"Author": "qianlifeng",
|
||||
"Version": "1.5.4",
|
||||
"Version": "1.6.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
||||
"ExecuteFileName": "Flow.Launcher.Plugin.Program.dll",
|
||||
|
|
|
|||
|
|
@ -73,7 +73,14 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
IcoPath = Image,
|
||||
Action = c =>
|
||||
{
|
||||
Execute(Process.Start, PrepareProcessStartInfo(m, c.SpecialKeyState.CtrlPressed));
|
||||
var runAsAdministrator = (
|
||||
c.SpecialKeyState.CtrlPressed &&
|
||||
c.SpecialKeyState.ShiftPressed &&
|
||||
!c.SpecialKeyState.AltPressed &&
|
||||
!c.SpecialKeyState.WinPressed
|
||||
);
|
||||
|
||||
Execute(Process.Start, PrepareProcessStartInfo(m, runAsAdministrator));
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
|
|
@ -106,7 +113,14 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
IcoPath = Image,
|
||||
Action = c =>
|
||||
{
|
||||
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
|
||||
var runAsAdministrator = (
|
||||
c.SpecialKeyState.CtrlPressed &&
|
||||
c.SpecialKeyState.ShiftPressed &&
|
||||
!c.SpecialKeyState.AltPressed &&
|
||||
!c.SpecialKeyState.WinPressed
|
||||
);
|
||||
|
||||
Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
@ -129,7 +143,14 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
IcoPath = Image,
|
||||
Action = c =>
|
||||
{
|
||||
Execute(Process.Start, PrepareProcessStartInfo(cmd));
|
||||
var runAsAdministrator = (
|
||||
c.SpecialKeyState.CtrlPressed &&
|
||||
c.SpecialKeyState.ShiftPressed &&
|
||||
!c.SpecialKeyState.AltPressed &&
|
||||
!c.SpecialKeyState.WinPressed
|
||||
);
|
||||
|
||||
Execute(Process.Start, PrepareProcessStartInfo(cmd, runAsAdministrator));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
@ -147,7 +168,14 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
IcoPath = Image,
|
||||
Action = c =>
|
||||
{
|
||||
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
|
||||
var runAsAdministrator = (
|
||||
c.SpecialKeyState.CtrlPressed &&
|
||||
c.SpecialKeyState.ShiftPressed &&
|
||||
!c.SpecialKeyState.AltPressed &&
|
||||
!c.SpecialKeyState.WinPressed
|
||||
);
|
||||
|
||||
Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Name": "Shell",
|
||||
"Description": "Provide executing commands from Flow Launcher",
|
||||
"Author": "qianlifeng",
|
||||
"Version": "1.4.3",
|
||||
"Version": "1.4.4",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
||||
"ExecuteFileName": "Flow.Launcher.Plugin.Shell.dll",
|
||||
|
|
|
|||
Loading…
Reference in a new issue