mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Add support for win32 packaged apps to run as admin (#2812)
* Updated UWP app to set entry point type for each app * Working run as admin for packaged app with permission * Updated UWP to allow apps with mediumIl trust level to be run as admin * cleanup variables not required
This commit is contained in:
parent
efe98f7fad
commit
e654999fdf
@ -21,6 +21,7 @@ using Windows.UI.Xaml.Media;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Wox.Plugin.SharedCommands;
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Program.Programs
|
namespace Microsoft.Plugin.Program.Programs
|
||||||
{
|
{
|
||||||
@ -257,10 +258,11 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
public string UserModelId { get; set; }
|
public string UserModelId { get; set; }
|
||||||
public string BackgroundColor { get; set; }
|
public string BackgroundColor { get; set; }
|
||||||
|
|
||||||
|
public string EntryPoint { get; set; }
|
||||||
public string Name => DisplayName;
|
public string Name => DisplayName;
|
||||||
public string Location => Package.Location;
|
public string Location => Package.Location;
|
||||||
|
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
|
public bool CanRunElevated {get;set;}
|
||||||
|
|
||||||
public string LogoUri { get; set; }
|
public string LogoUri { get; set; }
|
||||||
public string LogoPath { get; set; }
|
public string LogoPath { get; set; }
|
||||||
@ -311,24 +313,52 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
|
|
||||||
public List<ContextMenuResult> ContextMenus(IPublicAPI api)
|
public List<ContextMenuResult> ContextMenus(IPublicAPI api)
|
||||||
{
|
{
|
||||||
var contextMenus = new List<ContextMenuResult>
|
var contextMenus = new List<ContextMenuResult>();
|
||||||
{
|
|
||||||
new ContextMenuResult
|
|
||||||
{
|
|
||||||
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
|
||||||
Title = api.GetTranslation("wox_plugin_program_open_containing_folder"),
|
|
||||||
Glyph = "\xE838",
|
|
||||||
FontFamily = "Segoe MDL2 Assets",
|
|
||||||
AcceleratorKey = "E",
|
|
||||||
AcceleratorModifiers = "Control,Shift",
|
|
||||||
Action = _ =>
|
|
||||||
{
|
|
||||||
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location));
|
|
||||||
|
|
||||||
return true;
|
if (CanRunElevated)
|
||||||
}
|
{
|
||||||
}
|
contextMenus.Add(
|
||||||
};
|
new ContextMenuResult
|
||||||
|
{
|
||||||
|
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||||
|
Title = api.GetTranslation("wox_plugin_program_run_as_administrator"),
|
||||||
|
Glyph = "\xE7EF",
|
||||||
|
FontFamily = "Segoe MDL2 Assets",
|
||||||
|
AcceleratorKey = "Enter",
|
||||||
|
AcceleratorModifiers = "Control,Shift",
|
||||||
|
Action = _ =>
|
||||||
|
{
|
||||||
|
string command = "shell:AppsFolder\\" + UniqueIdentifier;
|
||||||
|
command.Trim();
|
||||||
|
command = Environment.ExpandEnvironmentVariables(command);
|
||||||
|
|
||||||
|
var info = ShellCommand.SetProcessStartInfo(command, verb: "runas");
|
||||||
|
info.UseShellExecute = true;
|
||||||
|
|
||||||
|
Process.Start(info);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
contextMenus.Add(
|
||||||
|
new ContextMenuResult
|
||||||
|
{
|
||||||
|
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||||
|
Title = api.GetTranslation("wox_plugin_program_open_containing_folder"),
|
||||||
|
Glyph = "\xE838",
|
||||||
|
FontFamily = "Segoe MDL2 Assets",
|
||||||
|
AcceleratorKey = "E",
|
||||||
|
AcceleratorModifiers = "Control,Shift",
|
||||||
|
Action = _ =>
|
||||||
|
{
|
||||||
|
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return contextMenus;
|
return contextMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,13 +391,36 @@ namespace Microsoft.Plugin.Program.Programs
|
|||||||
Description = manifestApp.GetStringValue("Description");
|
Description = manifestApp.GetStringValue("Description");
|
||||||
BackgroundColor = manifestApp.GetStringValue("BackgroundColor");
|
BackgroundColor = manifestApp.GetStringValue("BackgroundColor");
|
||||||
Package = package;
|
Package = package;
|
||||||
|
EntryPoint = manifestApp.GetStringValue("EntryPoint");
|
||||||
|
|
||||||
DisplayName = ResourceFromPri(package.FullName, DisplayName);
|
DisplayName = ResourceFromPri(package.FullName, DisplayName);
|
||||||
Description = ResourceFromPri(package.FullName, Description);
|
Description = ResourceFromPri(package.FullName, Description);
|
||||||
LogoUri = LogoUriFromManifest(manifestApp);
|
LogoUri = LogoUriFromManifest(manifestApp);
|
||||||
LogoPath = LogoPathFromUri(LogoUri);
|
LogoPath = LogoPathFromUri(LogoUri);
|
||||||
|
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
|
CanRunElevated = IfApplicationcanRunElevated();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IfApplicationcanRunElevated()
|
||||||
|
{
|
||||||
|
if (EntryPoint == "Windows.FullTrustApplication")
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var manifest = Package.Location + "\\AppxManifest.xml";
|
||||||
|
if (File.Exists(manifest))
|
||||||
|
{
|
||||||
|
var file = File.ReadAllText(manifest);
|
||||||
|
if(file.Contains("TrustLevel=\"mediumIL\"", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string ResourceFromPri(string packageFullName, string resourceReference)
|
internal string ResourceFromPri(string packageFullName, string resourceReference)
|
||||||
|
Loading…
Reference in New Issue
Block a user