@@ -267,6 +267,7 @@ public class Application : IProgram
267
267
public string Location => Package . Location ;
268
268
269
269
public bool Enabled { get ; set ; }
270
+ public bool CanRunElevated { get ; set ; }
270
271
271
272
public string LogoUri { get ; set ; }
272
273
public string LogoPath { get ; set ; }
@@ -320,7 +321,29 @@ public Result Result(string query, IPublicAPI api)
320
321
ContextData = this ,
321
322
Action = e =>
322
323
{
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
+
324
347
return true ;
325
348
}
326
349
} ;
@@ -354,6 +377,21 @@ public List<Result> ContextMenus(IPublicAPI api)
354
377
IcoPath = "Images/folder.png"
355
378
}
356
379
} ;
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
+
357
395
return contextMenus ;
358
396
}
359
397
@@ -377,6 +415,20 @@ await Task.Run(() =>
377
415
} ) ;
378
416
}
379
417
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
+
380
432
public Application ( AppxPackageHelper . IAppxManifestApplication manifestApp , UWP package )
381
433
{
382
434
// 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
403
455
LogoPath = LogoPathFromUri ( LogoUri ) ;
404
456
405
457
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 ;
406
480
}
407
481
408
482
internal string ResourceFromPri ( string packageFullName , string packageName , string rawReferenceValue )
0 commit comments