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 Wox.Plugin;
|
||||
using System.Reflection;
|
||||
using Wox.Plugin.SharedCommands;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
|
@ -257,10 +258,11 @@ namespace Microsoft.Plugin.Program.Programs
|
|||
public string UserModelId { get; set; }
|
||||
public string BackgroundColor { get; set; }
|
||||
|
||||
public string EntryPoint { get; set; }
|
||||
public string Name => DisplayName;
|
||||
public string Location => Package.Location;
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public bool CanRunElevated {get;set;}
|
||||
|
||||
public string LogoUri { get; set; }
|
||||
public string LogoPath { get; set; }
|
||||
|
@ -311,8 +313,35 @@ namespace Microsoft.Plugin.Program.Programs
|
|||
|
||||
public List<ContextMenuResult> ContextMenus(IPublicAPI api)
|
||||
{
|
||||
var contextMenus = new List<ContextMenuResult>
|
||||
var contextMenus = new List<ContextMenuResult>();
|
||||
|
||||
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,
|
||||
|
@ -327,8 +356,9 @@ namespace Microsoft.Plugin.Program.Programs
|
|||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
|
@ -361,6 +391,7 @@ namespace Microsoft.Plugin.Program.Programs
|
|||
Description = manifestApp.GetStringValue("Description");
|
||||
BackgroundColor = manifestApp.GetStringValue("BackgroundColor");
|
||||
Package = package;
|
||||
EntryPoint = manifestApp.GetStringValue("EntryPoint");
|
||||
|
||||
DisplayName = ResourceFromPri(package.FullName, DisplayName);
|
||||
Description = ResourceFromPri(package.FullName, Description);
|
||||
|
@ -368,6 +399,28 @@ namespace Microsoft.Plugin.Program.Programs
|
|||
LogoPath = LogoPathFromUri(LogoUri);
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue