mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Add run as administrator to Shell plugin settings
This commit is contained in:
@@ -9,6 +9,7 @@ using WindowsInput.Native;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin.SharedCommands;
|
||||
using Application = System.Windows.Application;
|
||||
using Control = System.Windows.Controls.Control;
|
||||
using Keys = System.Windows.Forms.Keys;
|
||||
@@ -164,16 +165,15 @@ namespace Wox.Plugin.Shell
|
||||
{
|
||||
command = command.Trim();
|
||||
command = Environment.ExpandEnvironmentVariables(command);
|
||||
var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? "" : "runas";
|
||||
|
||||
ProcessStartInfo info;
|
||||
if (_settings.Shell == Shell.Cmd)
|
||||
{
|
||||
var arguments = _settings.LeaveShellOpen ? $"/k \"{command}\"" : $"/c \"{command}\" & pause";
|
||||
info = new ProcessStartInfo
|
||||
{
|
||||
FileName = "cmd.exe",
|
||||
Arguments = arguments,
|
||||
};
|
||||
|
||||
info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, arguments, runAsAdministratorArg);
|
||||
}
|
||||
else if (_settings.Shell == Shell.Powershell)
|
||||
{
|
||||
@@ -186,11 +186,8 @@ namespace Wox.Plugin.Shell
|
||||
{
|
||||
arguments = $"\"{command} ; Read-Host -Prompt \\\"Press Enter to continue\\\"\"";
|
||||
}
|
||||
info = new ProcessStartInfo
|
||||
{
|
||||
FileName = "powershell.exe",
|
||||
Arguments = arguments
|
||||
};
|
||||
|
||||
info = ShellCommand.SetProcessStartInfo("powershell.exe", workingDirectory, arguments, runAsAdministratorArg);
|
||||
}
|
||||
else if (_settings.Shell == Shell.RunCommand)
|
||||
{
|
||||
@@ -200,21 +197,17 @@ namespace Wox.Plugin.Shell
|
||||
var filename = parts[0];
|
||||
if (ExistInPath(filename))
|
||||
{
|
||||
var arguemtns = parts[1];
|
||||
info = new ProcessStartInfo
|
||||
{
|
||||
FileName = filename,
|
||||
Arguments = arguemtns
|
||||
};
|
||||
var arguments = parts[1];
|
||||
info = ShellCommand.SetProcessStartInfo(filename, workingDirectory, arguments, runAsAdministratorArg);
|
||||
}
|
||||
else
|
||||
{
|
||||
info = new ProcessStartInfo(command);
|
||||
info = ShellCommand.SetProcessStartInfo(command, verb: runAsAdministratorArg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
info = new ProcessStartInfo(command);
|
||||
info = ShellCommand.SetProcessStartInfo(command, verb: runAsAdministratorArg);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -222,10 +215,7 @@ namespace Wox.Plugin.Shell
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
info.UseShellExecute = true;
|
||||
info.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
info.Verb = runAsAdministrator ? "runas" : "";
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user