@@ -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,27 @@ 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 )
332
+ {
333
+ if ( ! CanRunElevated )
334
+ {
335
+ return false ;
336
+ }
337
+
338
+ LaunchElevated ( ) ;
339
+ }
340
+ else
341
+ {
342
+ Launch ( api ) ;
343
+ }
344
+
324
345
return true ;
325
346
}
326
347
} ;
@@ -354,6 +375,21 @@ public List<Result> ContextMenus(IPublicAPI api)
354
375
IcoPath = "Images/folder.png"
355
376
}
356
377
} ;
378
+
379
+ if ( CanRunElevated )
380
+ {
381
+ contextMenus . Add ( new Result
382
+ {
383
+ Title = api . GetTranslation ( "flowlauncher_plugin_program_run_as_administrator" ) ,
384
+ Action = _ =>
385
+ {
386
+ LaunchElevated ( ) ;
387
+ return true ;
388
+ } ,
389
+ IcoPath = "Images/cmd.png"
390
+ } ) ;
391
+ }
392
+
357
393
return contextMenus ;
358
394
}
359
395
@@ -377,6 +413,20 @@ await Task.Run(() =>
377
413
} ) ;
378
414
}
379
415
416
+ private async void LaunchElevated ( )
417
+ {
418
+ string command = "shell:AppsFolder\\ " + UniqueIdentifier ;
419
+ command = Environment . ExpandEnvironmentVariables ( command . Trim ( ) ) ;
420
+
421
+ var info = new ProcessStartInfo ( command )
422
+ {
423
+ UseShellExecute = true ,
424
+ Verb = "runas" ,
425
+ } ;
426
+
427
+ Main . StartProcess ( Process . Start , info ) ;
428
+ }
429
+
380
430
public Application ( AppxPackageHelper . IAppxManifestApplication manifestApp , UWP package )
381
431
{
382
432
// This is done because we cannot use the keyword 'out' along with a property
@@ -403,6 +453,31 @@ public Application(AppxPackageHelper.IAppxManifestApplication manifestApp, UWP p
403
453
LogoPath = LogoPathFromUri ( LogoUri ) ;
404
454
405
455
Enabled = true ;
456
+ CanRunElevated = CanApplicationRunElevated ( ) ;
457
+ }
458
+
459
+ private bool CanApplicationRunElevated ( )
460
+ {
461
+ if ( EntryPoint == "Windows.FullTrustApplication" )
462
+ {
463
+ return true ;
464
+ }
465
+ else
466
+ {
467
+ var manifest = Package . Location + "\\ AppxManifest.xml" ;
468
+ if ( File . Exists ( manifest ) )
469
+ {
470
+ var file = File . ReadAllText ( manifest ) ;
471
+
472
+ // Using OrdinalIgnoreCase since this is used internally
473
+ if ( file . Contains ( "TrustLevel=\" mediumIL\" " , StringComparison . OrdinalIgnoreCase ) )
474
+ {
475
+ return true ;
476
+ }
477
+ }
478
+ }
479
+
480
+ return false ;
406
481
}
407
482
408
483
internal string ResourceFromPri ( string packageFullName , string packageName , string rawReferenceValue )
0 commit comments