@@ -267,6 +267,7 @@ public class Application : IProgram
267267 public string Location => Package . Location ;
268268
269269 public bool Enabled { get ; set ; }
270+ public bool CanRunElevated { get ; set ; }
270271
271272 public string LogoUri { get ; set ; }
272273 public string LogoPath { get ; set ; }
@@ -320,7 +321,29 @@ public Result Result(string query, IPublicAPI api)
320321 ContextData = this ,
321322 Action = e =>
322323 {
323- Launch ( api ) ;
324+ var elevated = (
325+ e . SpecialKeyState . CtrlPressed &&
326+ e . SpecialKeyState . ShiftPressed &&
327+ ! e . SpecialKeyState . AltPressed &&
328+ ! e . SpecialKeyState . WinPressed
329+ ) ;
330+
331+ if ( elevated && CanRunElevated )
332+ {
333+ LaunchElevated ( ) ;
334+ }
335+ else
336+ {
337+ Launch ( api ) ;
338+
339+ if ( elevated )
340+ {
341+ var title = "Plugin: Program" ;
342+ var message = api . GetTranslation ( "flowlauncher_plugin_program_run_as_administrator_not_supported_message" ) ;
343+ api . ShowMsg ( title , message , string . Empty ) ;
344+ }
345+ }
346+
324347 return true ;
325348 }
326349 } ;
@@ -354,6 +377,21 @@ public List<Result> ContextMenus(IPublicAPI api)
354377 IcoPath = "Images/folder.png"
355378 }
356379 } ;
380+
381+ if ( CanRunElevated )
382+ {
383+ contextMenus . Add ( new Result
384+ {
385+ Title = api . GetTranslation ( "flowlauncher_plugin_program_run_as_administrator" ) ,
386+ Action = _ =>
387+ {
388+ LaunchElevated ( ) ;
389+ return true ;
390+ } ,
391+ IcoPath = "Images/cmd.png"
392+ } ) ;
393+ }
394+
357395 return contextMenus ;
358396 }
359397
@@ -377,6 +415,20 @@ await Task.Run(() =>
377415 } ) ;
378416 }
379417
418+ private async void LaunchElevated ( )
419+ {
420+ string command = "shell:AppsFolder\\ " + UniqueIdentifier ;
421+ command = Environment . ExpandEnvironmentVariables ( command . Trim ( ) ) ;
422+
423+ var info = new ProcessStartInfo ( command )
424+ {
425+ UseShellExecute = true ,
426+ Verb = "runas" ,
427+ } ;
428+
429+ Main . StartProcess ( Process . Start , info ) ;
430+ }
431+
380432 public Application ( AppxPackageHelper . IAppxManifestApplication manifestApp , UWP package )
381433 {
382434 // This is done because we cannot use the keyword 'out' along with a property
@@ -403,6 +455,28 @@ public Application(AppxPackageHelper.IAppxManifestApplication manifestApp, UWP p
403455 LogoPath = LogoPathFromUri ( LogoUri ) ;
404456
405457 Enabled = true ;
458+ CanRunElevated = CanApplicationRunElevated ( ) ;
459+ }
460+
461+ private bool CanApplicationRunElevated ( )
462+ {
463+ if ( EntryPoint == "Windows.FullTrustApplication" )
464+ {
465+ return true ;
466+ }
467+
468+ var manifest = Package . Location + "\\ AppxManifest.xml" ;
469+ if ( File . Exists ( manifest ) )
470+ {
471+ var file = File . ReadAllText ( manifest ) ;
472+
473+ if ( file . Contains ( "TrustLevel=\" mediumIL\" " , StringComparison . OrdinalIgnoreCase ) )
474+ {
475+ return true ;
476+ }
477+ }
478+
479+ return false ;
406480 }
407481
408482 internal string ResourceFromPri ( string packageFullName , string packageName , string rawReferenceValue )
0 commit comments