-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathAdd_OpenWithCode.bat
More file actions
68 lines (59 loc) · 2.15 KB
/
Add_OpenWithCode.bat
File metadata and controls
68 lines (59 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@echo off
:: Batch script to add "Open with Code" to context menu (proper escaping)
:: Automatically elevates to Admin if needed
:: Check for admin rights
fltmc >nul 2>&1 || (
echo Requesting administrator privileges...
powershell -Command "Start-Process -Verb RunAs -FilePath '%~0'"
exit /b
)
:: Detect VS Code path (checks both default locations)
set "vscode_path="
for %%d in (
"%ProgramFiles%\Microsoft VS Code\Code.exe",
"%LocalAppData%\Programs\Microsoft VS Code\Code.exe"
) do if exist "%%~d" set "vscode_path=%%~d"
if not defined vscode_path (
echo Error: VS Code not found in:
echo - "%ProgramFiles%\Microsoft VS Code\Code.exe"
echo - "%LocalAppData%\Programs\Microsoft VS Code\Code.exe"
pause
exit /b 1
)
echo Found VS Code at: %vscode_path%
:: Generate .reg file with CORRECT escaping (like your original)
(
echo Windows Registry Editor Version 5.00
echo;
echo [-HKEY_CLASSES_ROOT\Directory\shell\OpenWithCode]
echo [-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenWithCode]
echo [-HKEY_CLASSES_ROOT\*\shell\OpenWithCode]
echo;
echo [HKEY_CLASSES_ROOT\Directory\shell\OpenWithCode]
echo @="Open with Code"
echo "Icon"="\"%vscode_path:\=\\%\",0"
echo;
echo [HKEY_CLASSES_ROOT\Directory\shell\OpenWithCode\command]
echo @="\"%vscode_path:\=\\%\" \"%%1\""
echo;
echo [HKEY_CLASSES_ROOT\Directory\Background\shell\OpenWithCode]
echo @="Open with Code"
echo "Icon"="\"%vscode_path:\=\\%\",0"
echo;
echo [HKEY_CLASSES_ROOT\Directory\Background\shell\OpenWithCode\command]
echo @="\"%vscode_path:\=\\%\" \"%%V\""
echo;
echo [HKEY_CLASSES_ROOT\*\shell\OpenWithCode]
echo @="Open with Code"
echo "Icon"="\"%vscode_path:\=\\%\",0"
echo;
echo [HKEY_CLASSES_ROOT\*\shell\OpenWithCode\command]
echo @="\"%vscode_path:\=\\%\" \"%%1\""
) > "%temp%\OpenWithCode.reg"
:: Apply changes silently
regedit /s "%temp%\OpenWithCode.reg"
:: Restart File Explorer to apply changes
taskkill /f /im explorer.exe >nul
start explorer.exe
echo Success! "Open with Code" added to context menu.
pause