mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Just standardizing built-in extensions to use a `internal sealed class Icons` for all their non-dynamic icons. Looks like a LOT of changes, but it's icons all the way down.
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.CmdPal.Ext.Apps.Properties;
|
|
using Microsoft.CmdPal.Ext.Apps.Utils;
|
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
|
|
|
namespace Microsoft.CmdPal.Ext.Apps.Commands;
|
|
|
|
internal sealed partial class RunAsAdminCommand : InvokableCommand
|
|
{
|
|
private readonly string _target;
|
|
private readonly string _parentDir;
|
|
private readonly bool _packaged;
|
|
|
|
public RunAsAdminCommand(string target, string parentDir, bool packaged)
|
|
{
|
|
Name = Resources.run_as_administrator;
|
|
Icon = Icons.RunAsAdminIcon;
|
|
|
|
_target = target;
|
|
_parentDir = parentDir;
|
|
_packaged = packaged;
|
|
}
|
|
|
|
internal static async Task RunAsAdmin(string target, string parentDir, bool packaged)
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
if (packaged)
|
|
{
|
|
var command = "shell:AppsFolder\\" + target;
|
|
command = Environment.ExpandEnvironmentVariables(command.Trim());
|
|
|
|
var info = ShellCommand.SetProcessStartInfo(command, verb: "runas");
|
|
info.UseShellExecute = true;
|
|
info.Arguments = string.Empty;
|
|
Process.Start(info);
|
|
}
|
|
else
|
|
{
|
|
var info = ShellCommand.GetProcessStartInfo(target, parentDir, string.Empty, ShellCommand.RunAsType.Administrator);
|
|
|
|
Process.Start(info);
|
|
}
|
|
});
|
|
}
|
|
|
|
public override CommandResult Invoke()
|
|
{
|
|
_ = RunAsAdmin(_target, _parentDir, _packaged).ConfigureAwait(false);
|
|
|
|
return CommandResult.Dismiss();
|
|
}
|
|
}
|