Skip to content

Commit ffd22d7

Browse files
committed
add run as administration when holding ctrl and shift to Program and Explorer plugins
1 parent a87cea7 commit ffd22d7

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

Flow.Launcher/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<KeyBinding Key="Home" Modifiers="Alt" Command="{Binding SelectFirstResultCommand}"></KeyBinding>
4747
<KeyBinding Key="O" Modifiers="Ctrl" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
4848
<KeyBinding Key="H" Modifiers="Ctrl" Command="{Binding LoadHistoryCommand}"></KeyBinding>
49+
<KeyBinding Key="Enter" Modifiers="Ctrl+Shift" Command="{Binding OpenResultCommand}"></KeyBinding>
4950
<KeyBinding Key="Enter" Modifiers="Shift" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
5051
<KeyBinding Key="Enter" Command="{Binding OpenResultCommand}"></KeyBinding>
5152
<KeyBinding Key="Enter" Modifiers="Ctrl" Command="{Binding OpenResultCommand}"></KeyBinding>

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Flow.Launcher.Infrastructure;
22
using Flow.Launcher.Plugin.SharedCommands;
33
using System;
4+
using System.Diagnostics;
45
using System.IO;
56
using System.Linq;
7+
using System.Threading.Tasks;
68
using System.Windows;
79

810
namespace Flow.Launcher.Plugin.Explorer.Search
@@ -127,7 +129,26 @@ internal static Result CreateFileResult(string filePath, Query query, int score
127129
{
128130
try
129131
{
130-
if (c.SpecialKeyState.CtrlPressed)
132+
if (File.Exists(filePath) && c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed)
133+
{
134+
Task.Run(() =>
135+
{
136+
try
137+
{
138+
Process.Start(new ProcessStartInfo
139+
{
140+
FileName = filePath,
141+
UseShellExecute = true,
142+
Verb = "runas",
143+
});
144+
}
145+
catch (Exception e)
146+
{
147+
MessageBox.Show(e.Message, "Could not start " + filePath);
148+
}
149+
});
150+
}
151+
else if (c.SpecialKeyState.CtrlPressed)
131152
{
132153
FilesFolders.OpenContainingFolder(filePath);
133154
}

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,24 @@ public Result Result(string query, IPublicAPI api)
102102
Score = matchResult.Score,
103103
TitleHighlightData = matchResult.MatchData,
104104
ContextData = this,
105-
Action = _ =>
105+
Action = c =>
106106
{
107+
var runAsAdmin = (
108+
c.SpecialKeyState.CtrlPressed &&
109+
c.SpecialKeyState.ShiftPressed &&
110+
!c.SpecialKeyState.AltPressed &&
111+
!c.SpecialKeyState.WinPressed
112+
);
113+
107114
var info = new ProcessStartInfo
108115
{
109116
FileName = LnkResolvedPath ?? FullPath,
110117
WorkingDirectory = ParentDirectory,
111-
UseShellExecute = true
118+
UseShellExecute = true,
119+
Verb = runAsAdmin ? "runas" : null
112120
};
113121

114-
Main.StartProcess(Process.Start, info);
122+
Task.Run(() => Main.StartProcess(Process.Start, info));
115123

116124
return true;
117125
}

0 commit comments

Comments
 (0)