当前位置: 首页 > news >正文

win11修复右键菜单缺失在此处打开终端

修复powershell和Linux子系统右键空白处缺失

使用中文出出现乱码的情况,没搞中文版,直接就全英文版

@echo off
:: Idempotent context menu installer for Windows Terminal / WSL / Windows Terminal (Admin)
:: Icon fixes: default to cmd.exe (WT icon) & wsl.exe (WSL icon)
:: Usage:
::   context_term_wsl_en.bat                  -> install/update (WSL default)
::   context_term_wsl_en.bat /kali            -> WSL = "wsl.exe -d kali-linux"
::   context_term_wsl_en.bat /custom:Name     -> WSL = "wsl.exe -d Name"
::   context_term_wsl_en.bat /icon:PATH       -> use custom icon file for WT (EXE/DLL/ICO)
::   context_term_wsl_en.bat /iconauto        -> try to use real Windows Terminal EXE as icon (may not show)
::   context_term_wsl_en.bat /uninstall       -> remove all itemssetlocal
chcp 65001 >nul:: --- Admin check ---
net session >nul 2>&1
if %errorlevel% neq 0 (echo [!] Please run this script as Administrator.pauseexit /b 1
):: --- Defaults ---
set "WSL_CMD=wsl.exe"
:: default icons (guaranteed to display)
set "ICON_WT=%SystemRoot%\System32\cmd.exe"
set "ICON_WSL=%SystemRoot%\System32\wsl.exe":: --- Parse args ---
for %%A in (%*) do (if /i "%%~A"=="/kali" set "WSL_CMD=wsl.exe -d kali-linux"
)for %%A in (%*) do (for /f "tokens=1,2 delims=:" %%p in ("%%~A") do (if /i "%%p"=="/custom" if not "%%q"=="" set "WSL_CMD=wsl.exe -d %%q"if /i "%%p"=="/icon"   if not "%%q"=="" set "ICON_WT=%%q")
):: Try to use real WT icon (can fail silently due to WindowsApps ACLs)
for %%A in (%*) do (if /i "%%~A"=="/iconauto" (for /f "usebackq tokens=*" %%P in (`powershell -NoProfile -Command "(Get-AppxPackage -Name Microsoft.WindowsTerminal -ErrorAction SilentlyContinue | Select -Expand InstallLocation)"`) do (if not "%%~P"=="" set "ICON_WT=%%~P\WindowsTerminal.exe"))
):: --- Registry keys (fixed names to avoid duplicates) ---
set "K_BG_WT=HKCR\Directory\Background\shell\WindowsTerminal"
set "K_BG_WT_CMD=HKCR\Directory\Background\shell\WindowsTerminal\command"
set "K_BG_WTA=HKCR\Directory\Background\shell\WindowsTerminalAdmin"
set "K_BG_WTA_CMD=HKCR\Directory\Background\shell\WindowsTerminalAdmin\command"
set "K_BG_WSL=HKCR\Directory\Background\shell\WSL"
set "K_BG_WSL_CMD=HKCR\Directory\Background\shell\WSL\command"set "K_DIR_WT=HKCR\Directory\shell\WindowsTerminal"
set "K_DIR_WT_CMD=HKCR\Directory\shell\WindowsTerminal\command"
set "K_DIR_WTA=HKCR\Directory\shell\WindowsTerminalAdmin"
set "K_DIR_WTA_CMD=HKCR\Directory\shell\WindowsTerminalAdmin\command"
set "K_DIR_WSL=HKCR\Directory\shell\WSL"
set "K_DIR_WSL_CMD=HKCR\Directory\shell\WSL\command":: --- Uninstall ---
if /i "%~1"=="/uninstall" (echo [0/0] Uninstalling context menu items...for %%K in ("%K_BG_WT%" "%K_BG_WTA%" "%K_BG_WSL%" "%K_DIR_WT%" "%K_DIR_WTA%" "%K_DIR_WSL%") do reg delete "%%~K" /f >nul 2>&1echo Done. Restarting Explorer...taskkill /f /im explorer.exe >nul 2>&1start explorer.exeexit /b 0
)echo [0/3] Cleaning previous items (safe if missing)...
for %%K in ("%K_BG_WT%" "%K_BG_WTA%" "%K_BG_WSL%" "%K_DIR_WT%" "%K_DIR_WTA%" "%K_DIR_WSL%") do reg delete "%%~K" /f >nul 2>&1:: -------- 1) Windows Terminal (normal) --------
echo [1/3] Installing "Open Windows Terminal here"... (Icon: %ICON_WT%)
:: Background (blank area) -> %V
powershell -NoProfile -ExecutionPolicy Bypass -Command "New-Item -Path 'Registry::%K_BG_WT%' -Force | Out-Null; New-Item -Path 'Registry::%K_BG_WT_CMD%' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_BG_WT%' -Name '(default)' -Value 'Open Windows Terminal here'; Set-ItemProperty -Path 'Registry::%K_BG_WT%' -Name 'Icon' -Value '%ICON_WT%'; New-ItemProperty -Path 'Registry::%K_BG_WT%' -Name 'NoWorkingDirectory' -PropertyType String -Value '' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_BG_WT_CMD%' -Name '(default)' -Value 'wt.exe -d ""%%V""'":: Folder -> %1
powershell -NoProfile -ExecutionPolicy Bypass -Command "New-Item -Path 'Registry::%K_DIR_WT%' -Force | Out-Null; New-Item -Path 'Registry::%K_DIR_WT_CMD%' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_DIR_WT%' -Name '(default)' -Value 'Open Windows Terminal here'; Set-ItemProperty -Path 'Registry::%K_DIR_WT%' -Name 'Icon' -Value '%ICON_WT%'; New-ItemProperty -Path 'Registry::%K_DIR_WT%' -Name 'NoWorkingDirectory' -PropertyType String -Value '' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_DIR_WT_CMD%' -Name '(default)' -Value 'wt.exe -d ""%%1""'":: -------- 2) WSL --------
echo [2/3] Installing "Open Linux Shell (WSL) here"... (Icon: %ICON_WSL%)
:: Background
powershell -NoProfile -ExecutionPolicy Bypass -Command "New-Item -Path 'Registry::%K_BG_WSL%' -Force | Out-Null; New-Item -Path 'Registry::%K_BG_WSL_CMD%' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_BG_WSL%' -Name '(default)' -Value 'Open Linux Shell (WSL) here'; Set-ItemProperty -Path 'Registry::%K_BG_WSL%' -Name 'Icon' -Value '%ICON_WSL%'; New-ItemProperty -Path 'Registry::%K_BG_WSL%' -Name 'NoWorkingDirectory' -PropertyType String -Value '' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_BG_WSL_CMD%' -Name '(default)' -Value '%WSL_CMD%'":: Folder
powershell -NoProfile -ExecutionPolicy Bypass -Command "New-Item -Path 'Registry::%K_DIR_WSL%' -Force | Out-Null; New-Item -Path 'Registry::%K_DIR_WSL_CMD%' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_DIR_WSL%' -Name '(default)' -Value 'Open Linux Shell (WSL) here'; Set-ItemProperty -Path 'Registry::%K_DIR_WSL%' -Name 'Icon' -Value '%ICON_WSL%'; New-ItemProperty -Path 'Registry::%K_DIR_WSL%' -Name 'NoWorkingDirectory' -PropertyType String -Value '' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_DIR_WSL_CMD%' -Name '(default)' -Value '%WSL_CMD%'":: -------- 3) Windows Terminal (Admin) --------
echo [3/3] Installing "Open Windows Terminal (Admin)"... (Icon: %ICON_WT%)
:: Background
powershell -NoProfile -ExecutionPolicy Bypass -Command "New-Item -Path 'Registry::%K_BG_WTA%' -Force | Out-Null; New-Item -Path 'Registry::%K_BG_WTA_CMD%' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_BG_WTA%' -Name '(default)' -Value 'Open Windows Terminal (Admin)'; Set-ItemProperty -Path 'Registry::%K_BG_WTA%' -Name 'Icon' -Value '%ICON_WT%'; New-ItemProperty -Path 'Registry::%K_BG_WTA%' -Name 'HasLUAShield' -PropertyType String -Value '' -Force | Out-Null; New-ItemProperty -Path 'Registry::%K_BG_WTA%' -Name 'NoWorkingDirectory' -PropertyType String -Value '' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_BG_WTA_CMD%' -Name '(default)' -Value 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ""Start-Process wt.exe -Verb RunAs -WorkingDirectory ''%%V''""'":: Folder
powershell -NoProfile -ExecutionPolicy Bypass -Command "New-Item -Path 'Registry::%K_DIR_WTA%' -Force | Out-Null; New-Item -Path 'Registry::%K_DIR_WTA_CMD%' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_DIR_WTA%' -Name '(default)' -Value 'Open Windows Terminal (Admin)'; Set-ItemProperty -Path 'Registry::%K_DIR_WTA%' -Name 'Icon' -Value '%ICON_WT%'; New-ItemProperty -Path 'Registry::%K_DIR_WTA%' -Name 'HasLUAShield' -PropertyType String -Value '' -Force | Out-Null; New-ItemProperty -Path 'Registry::%K_DIR_WTA%' -Name 'NoWorkingDirectory' -PropertyType String -Value '' -Force | Out-Null; Set-ItemProperty -Path 'Registry::%K_DIR_WTA_CMD%' -Name '(default)' -Value 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ""Start-Process wt.exe -Verb RunAs -WorkingDirectory ''%%1''""'"echo.
echo ✅ Done. Restarting Explorer to refresh menus...
taskkill /f /im explorer.exe >nul 2>&1
start explorer.exeecho.
echo Installed items with icons:
echo - Windows Terminal: %ICON_WT%
echo - WSL:              %ICON_WSL%
echo.
echo Tips:
echo   - Use "/kali" or "/custom:Kali-Linux" to target Kali
echo   - Use "/icon:FULL\PATH\to\your.ico" to force a specific icon for WT
echo   - Use "/iconauto" to try Windows Terminal's own icon (may not render)
echo   - Uninstall with "/uninstall"
pause
http://www.dtcms.com/a/443505.html

相关文章:

  • linux(sem信号量 + 线程池)
  • 电子商务网站制作步骤wordpress首页加图片
  • 北京做网站哪家公司最好自建站网址
  • C++循环结构详解:从入门到精通
  • 一键搭建网站windows网络工程师含金量高吗
  • 使用C语言制作简易的三子棋游戏
  • 网站营销推广企业高端网站定制的案例
  • 商丘公司做网站用心做的网站
  • 网站建设与管理可以专升本吗wordpress 电影模版
  • 网站设计基本功能怎么制作一个免费的网站模板
  • 18年手机网站开发公司质量管理体系
  • 简约网站首页江门做网站公司开网络公司
  • 体育局网站建设方案刚做还网站第一时间抓取
  • 搭建企业知识库windows10+Ollama+deepseek+ragflower
  • 基于华为openEuler部署my-mind思维导图工具
  • Python学习之Day05学习(定制数据对象,面向对象)
  • 公司网站 备案济南网站营销
  • 算法 | Recursion vs Iteration
  • 征求网站建设WordPress禁用评论回收站
  • SDKMAN管理 Java 多版本
  • 找在家做的兼职上什么网站好wordpress插件重写
  • 织梦网站新闻列表调用挣钱最快的小游戏
  • 创造力网站设计seo关键词搜索和优化
  • 数据传输对象(DTO)中什么时候用int,什么时候用Integer
  • 广州注册公司核名在哪个网站网站建费用
  • 可以上传自己做的视频的网站网站维护的注意事项
  • 做暧嗳xo小视频网站深度开发
  • 电商类网站开发网上搞钱的野路子
  • 网站打不开服务器错误建设银行官网登录入口
  • HandlerThread源码阅读