存储为bat
文件
@ECHO OFF PUSHD %~DP0 chcp 65001 TITLE VSCode Md "%WinDir%\System32\test_permissions" 2>NUL||(Echo 请使用右键管理员身份运行&&Pause >NUL&&Exit) Rd "%WinDir%\System32\test_permissions" 2>NUL SetLocal EnableDelayedExpansion SET /P ST=输入a添加右键菜单,输入d删除右键菜单: if /I "%ST%"=="a" goto Add if /I "%ST%"=="d" goto Remove :Add reg add "HKEY_CLASSES_ROOT\*\shell\VSCode" /t REG_SZ /v "" /d "&Open With Code" /f reg add "HKEY_CLASSES_ROOT\*\shell\VSCode" /t REG_EXPAND_SZ /v "Icon" /d "%~dp0Code.exe" /f reg add "HKEY_CLASSES_ROOT\*\shell\VSCode\command" /t REG_SZ /v "" /d "%~dp0Code.exe \"%%1\"" /f reg add "HKEY_CLASSES_ROOT\Directory\shell\VSCode" /t REG_SZ /v "" /d "&Open With Code" /f reg add "HKEY_CLASSES_ROOT\Directory\shell\VSCode" /t REG_EXPAND_SZ /v "Icon" /d "%~dp0Code.exe" /f reg add "HKEY_CLASSES_ROOT\Directory\shell\VSCode\command" /t REG_SZ /v "" /d "%~dp0Code.exe \"%%V\"" /f reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode" /t REG_SZ /v "" /d "&Open With Code" /f reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode" /t REG_EXPAND_SZ /v "Icon" /d "%~dp0Code.exe" /f reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\command" /t REG_SZ /v "" /d "%~dp0Code.exe \"%%V\"" /f exit :Remove reg delete "HKEY_CLASSES_ROOT\*\shell\VSCode" /f reg delete "HKEY_CLASSES_ROOT\Directory\shell\VSCode" /f reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode" /f exit