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