windows-terminal - 从 Windows 终端内以提升的权限打开 Windows 终端

标签 windows-terminal

这里有很多问题询问如何从powershell提升权限,几乎所有人都推荐这个命令:

Start-Process -Verb RunAs powershell.exe .....
(或用于 Powershell Core 的 pwsh.exe)
这是有效的,在通过 UAC 块验证访问后,它会打开一个具有提升权限的新 Powershell 窗口。
但是,当我使用 Powershell 时,我在 Windows 终端(Windows 10 的新终端应用程序)中执行此操作,我想打开一个具有提升权限的新 Windows 终端实例,而不仅仅是一个 Powershell 窗口。
所以我尝试了这些命令:
Start-Process -Verb RunAs wt
Start-Process -Verb RunAs wt.exe
Start-Process -Verb RunAs (Get-Command wt)
Start-Process -Verb RunAs "C:\Users\lasse\AppData\Local\Microsoft\WindowsApps\wt.exe"
他们都失败了:

Start-Process: This command cannot be run due to the error: The file cannot be accessed by the system..


我假设这与我的配置文件中可执行文件所在的位置有关,但是如果我右键单击任务栏上的 Windows 终端图标并选择以管理员身份运行它,它会打开得很好。这就是我想要复制的。
那么有没有办法让我修改我在上面尝试过的命令,或者更改一些可以使其工作的访问设置?
对于我的特定实例,我只是想让弹出管理终端更简单,我不需要提升任意命令的方法,然后我会很乐意使用我已经在这里展示的命令。

最佳答案

目前您无法打开高架 wt.exe没有解决方法的命令行 session 。解决方法包括使用 gsudo , 使用 Task Scheduler (我测试了这个并且它有效,但您需要使用 wt.exe 的完整路径,您可以跳过快捷方式创建步骤)或者如果您可以使用键盘快捷键,最简单的方法;使用键盘快捷键从任务栏以管理员身份运行 Windows 终端。
对于您的用例:

For my specific instance, I simply want to make it simpler to pop open an admin terminal, I don't need a way to elevate arbitrary commands, then I will happily use the commands I have already shown here.


最简单的方法将起作用:
将 Windows 终端固定为任务栏上的第一项。然后按 Win+Ctrl+Shift+1 以管理员身份打开它。
如果您确实必须从 Windows 终端内的命令行启动 Windows 终端,请在任务计划程序中创建一个任务:
  • 为任务命名,选中“以最高权限运行”。
  • 选择“操作”选项卡,单击“新建”,选择“启动程序”作为操作。把完整路径放到wt.exe在“程序/脚本字段”中。单击确定。再次单击确定。
  • 单击“条件”选项卡,取消选中“仅当计算机使用交流电源时才启动任务”。
  • 单击“设置”选项卡,确保选中“允许按需运行任务”并取消选中“如果运行时间超过则停止任务”。
  • 最后,在您的 shell (Powershell) 中,通过运行以下命令启动提升的 Windows 终端 session :schtasks /run /TN "TASK_NAME"其中 TASK_NAME 是您在步骤 1 中为任务指定的名称。
  • 关于windows-terminal - 从 Windows 终端内以提升的权限打开 Windows 终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62496779/

    相关文章:

    cmd - 使用 PHP 在 CLI/shell/终端中打印表情符号/外来字符

    powershell-4.0 - 如何从powershell提示中删除 "username@host"?

    windows-terminal - 任何人都知道如何像这样美化 Windows 终端

    docker - 无法使用新的 Windows 终端在 WSL2 中启动 Docker

    windows-terminal - 如何通过在 Powershell(Windows 终端)中运行特定命令来打开新选项卡?

    bash - 使用 shell 脚本打开新的 Ubuntu 选项卡,然后在这些新选项卡中运行命令

    powershell - 从CLI启动Windows终端并传递可执行命令以运行

    utf-8 - 如何在 Windows 终端应用程序 (UWP) 中将默认编码更改为 UTF-8

    git - Windows 终端 - 通过 oh-my-posh/posh-git Set-Theme 错误自定义 PowerShell?