mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[PT Run] Run as user feature (#17283)
* run as different user * fix tests * Update src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs * fix typo
This commit is contained in:
@@ -158,6 +158,8 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
// We don't add context menu to 'run as different user', because UWP applications normally installed per user and not for all users.
|
||||
}
|
||||
|
||||
contextMenus.Add(
|
||||
|
||||
@@ -266,7 +266,24 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
Action = _ =>
|
||||
{
|
||||
var info = GetProcessStartInfo(queryArguments, true);
|
||||
var info = GetProcessStartInfo(queryArguments, RunAsType.Administrator);
|
||||
Task.Run(() => Main.StartProcess(Process.Start, info));
|
||||
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
contextMenus.Add(new ContextMenuResult
|
||||
{
|
||||
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
Title = Properties.Resources.wox_plugin_program_run_as_user,
|
||||
Glyph = "\xE7EE",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.U,
|
||||
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
Action = _ =>
|
||||
{
|
||||
var info = GetProcessStartInfo(queryArguments, RunAsType.OtherUser);
|
||||
Task.Run(() => Main.StartProcess(Process.Start, info));
|
||||
|
||||
return true;
|
||||
@@ -317,7 +334,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
private ProcessStartInfo GetProcessStartInfo(string programArguments, bool runAsAdmin = false)
|
||||
private ProcessStartInfo GetProcessStartInfo(string programArguments, RunAsType runAs = RunAsType.None)
|
||||
{
|
||||
return new ProcessStartInfo
|
||||
{
|
||||
@@ -325,10 +342,17 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
WorkingDirectory = ParentDirectory,
|
||||
UseShellExecute = true,
|
||||
Arguments = programArguments,
|
||||
Verb = runAsAdmin ? "runas" : string.Empty,
|
||||
Verb = runAs == RunAsType.Administrator ? "runAs" : runAs == RunAsType.OtherUser ? "runAsUser" : string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
private enum RunAsType
|
||||
{
|
||||
None,
|
||||
Administrator,
|
||||
OtherUser,
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ExecutableName;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Microsoft.Plugin.Program.Properties {
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Resources {
|
||||
@@ -203,5 +203,14 @@ namespace Microsoft.Plugin.Program.Properties {
|
||||
return ResourceManager.GetString("wox_plugin_program_run_as_administrator", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Run as different user (Ctrl+Shift+U).
|
||||
/// </summary>
|
||||
public static string wox_plugin_program_run_as_user {
|
||||
get {
|
||||
return ResourceManager.GetString("wox_plugin_program_run_as_user", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,4 +165,7 @@
|
||||
<data name="powertoys_run_plugin_program_uwp_failed" xml:space="preserve">
|
||||
<value>Can't start UWP</value>
|
||||
</data>
|
||||
<data name="wox_plugin_program_run_as_user" xml:space="preserve">
|
||||
<value>Run as different user (Ctrl+Shift+U)</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user