管理员权限用不了, 后面再修修 使用 gsudo 的方法启用管理员权限

参考文档

Windows Terminal添加到右键菜单

效果

先放上最终效果

effect

注意

  • 部分要Lantern替换为自己的用户名

  • 配置Ubuntu 和 Windows Terminal 要注意自己的版本和文件目录

    • 比如:Microsoft.WindowsTerminal_0.11.1191.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe中的0.11.1191.0_x64__8wekyb3d8bbwe
    • 以及: CanonicalGroupLimited.Ubuntu18.04onWindows_2020.1804.7.0_x64__79rhkp1fndgsc\\ubuntu1804.exe中的Ubuntu18.04onWindows_2020.1804.7.0_x64__79rhkp1fndgscubuntu1804.exe
    • 这里推荐 Everything 在目录C:\\Program Files\\WindowsApps进行关键字CanonicalGroupLimitedMicrosoft.WindowsTerminal搜索, 找到文件名后修改reg文件内容中对应的文件目录以及文件名(其实文件数不多, 直接看也可以), 不过首先要取得权限: Win10下WindowsApps权限怎么获取-百度经验
  • 启动对应终端名字需要一致

    • 形如"cmd.exe /s /c pushd \"%V\" & start wt -p \"Ubuntu\" -d ."中的"Ubuntu"

    • 或者是 C:\\Users\\Lantern\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"Ubuntu\" -d . 中的Ubuntu

    • 需要和配置文件中的名字相一致, 如下图所示

      same_name

  • 下面的文件内容中, 我添加了Git Bash, 若不需要, 可以自行删除; 需要, 则自行修改文件目录和Windos Terminal配置文件(修改配置文件可参考上图)

  • 使用管理员权限要按照gsudo, PowerShell 输入下列命令即可, 管理员权限

    PowerShell -Command "Set-ExecutionPolicy RemoteSigned -scope Process; iwr -useb https://raw.githubusercontent.com/gerardog/gsudo/master/installgsudo.ps1 | iex"

注册表reg文件内容

Windows Registry Editor Version 5.00

; Windows terminal

[HKEY_CLASSES_ROOT\Directory\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"


[HKEY_CLASSES_ROOT\Directory\background\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"

[HKEY_CLASSES_ROOT\Directory\LibraryFolder\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"

[HKEY_CLASSES_ROOT\Drive\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"

[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\MenuWindowsTerminal]
"MUIVerb"="Windows Terminal"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminal"

; Windows Terminal SUDO

[HKEY_CLASSES_ROOT\Directory\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"


[HKEY_CLASSES_ROOT\Directory\background\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"

[HKEY_CLASSES_ROOT\Directory\LibraryFolder\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"

[HKEY_CLASSES_ROOT\Drive\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"

[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\MenuWindowsTerminalSudo]
"MUIVerb"="Windows Terminal (Admin)"
"Icon"="C:\\Users\\Lantern\\AppData\\Local\\terminal\\terminal.ico"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\MenuWindowsTerminalSudo"

; Subcommands

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\CMD]
"MUIVerb"="CMD"
"ExtendedSubCommandsKey"=-
"Icon"="imageres.dll, -5323"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\CMD\command]
@="C:\\Users\\Lantern\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"cmd\" -d ."

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Powershell]
"MUIVerb"="Windows PowerShell"
"ExtendedSubCommandsKey"=-
"Icon"="imageres.dll, -5372"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Powershell\command]
@="C:\\Users\\Lantern\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"Windows PowerShell\" -d ."

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Ubuntu]
"MUIVerb"="Ubuntu"
"ExtendedSubCommandsKey"=-
"Icon"="C:\\Program Files\\WindowsApps\\CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2020.423.0_x64__79rhkp1fndgsc\\ubuntu1804.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Ubuntu\command]
@="C:\\Users\\Lantern\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"Ubuntu\" -d ."

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Git Bash]
"MUIVerb"="Git Bash"
"ExtendedSubCommandsKey"=-
"Icon"="D:\\Program Files\\Git\\git-bash.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminal\shell\Git Bash\command]
@="C:\\Users\\Lantern\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -p \"Git Bash\" -d ."

; Subcommands Sudo

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\CMD]
"MUIVerb"="CMD"
"HasLUAShield"=""
"Icon"="imageres.dll, -5324"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\CMD\command]
@="cmd.exe /s /c pushd \"%V\" & gsudo start wt -p \"cmd\" -d ."

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Powershell]
"MUIVerb"="Windows PowerShell"
"HasLUAShield"=""
"Icon"="imageres.dll, -5373"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Powershell\command]
@="cmd.exe /s /c pushd \"%V\" & gsudo start wt -p \"Windows PowerShell\" -d ."

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Ubuntu]
"MUIVerb"="Ubuntu"
"HasLUAShield"=""
"Icon"="C:\\Program Files\\WindowsApps\\CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2020.423.0_x64__79rhkp1fndgsc\\ubuntu1804.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Ubuntu\command]
@="cmd.exe /s /c pushd \"%V\" & gsudo start wt -p \"Ubuntu\" -d ."

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Git Bash]
"MUIVerb"="Git Bash"
"HasLUAShield"=""
"Icon"="D:\\Program Files\\Git\\git-bash.exe"

[HKEY_CLASSES_ROOT\Directory\ContextMenus\MenuWindowsTerminalSudo\shell\Git Bash\command]
@="cmd.exe /s /c pushd \"%V\" & gsudo start wt -p \"Git Bash\" -d ."

参考

使用系統管理員身分開啟 Windows Terminal 分頁

Windows Terminal添加到右键菜单