简体   繁体   中英

How to open VSCode Remote-WSL by right click

I would like to open the current folder on VSCode Remote-WSL by right click from Windows File Explorer. How can I make it? Thank you in advance.

To add Windows context menu for a directory to open it in Visual Studio Code within Remote WSL, add these windows registry keys as admin:

reg add "HKEY_CLASSES_ROOT\Directory\shell\WSLVSCode\command" /t REG_EXPAND_SZ /d "wsl.exe code `wslpath '%1'`"
reg add "HKEY_CLASSES_ROOT\Directory\shell\WSLVSCode" /t REG_EXPAND_SZ /d "Open in WSL VSCode"
reg add "HKEY_CLASSES_ROOT\Directory\shell\WSLVSCode" /v Icon /t REG_EXPAND_SZ /d "C:\Users\User\AppData\Local\Programs\Microsoft VS Code\Code.exe"

Update the correct path for icon file.

Try this for 'Open folder in WSL':
Make a registry file (.reg), paste code and run:

Windows Registry Editor Version 5.00

; Delete old entries [-HKEY_CLASSES_ROOT\\Directory\\shell\\VSCode] [-HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\VSCode]

; Add a sub-menu for right click on a folder [HKEY_CLASSES_ROOT\\Directory\\shell\\VSCode] "MUIVerb"="Visual Studio Code" "ExtendedSubCommandsKey"="Directory\\ContextMenus\\VSCode" "Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

; Add a sub-menu for right click on the background [HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\VSCode] "MUIVerb"="Visual Studio Code" "ExtendedSubCommandsKey"="Directory\\ContextMenus\\VSCode" "Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

[HKEY_CLASSES_ROOT\\Directory\\ContextMenus\\VSCode]

[HKEY_CLASSES_ROOT\\Directory\\ContextMenus\\VSCode\\shell]

; Set up text and icons [HKEY_CLASSES_ROOT\\Directory\\ContextMenus\\VSCode\\shell\\open] "MUIVerb"="Open folder" "Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

[HKEY_CLASSES_ROOT\\Directory\\ContextMenus\\VSCode\\shell\\openwsl] "MUIVerb"="Open folder in WSL" "Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

; Set up commands [HKEY_CLASSES_ROOT\\Directory\\ContextMenus\\VSCode\\shell\\open\\command] @=""C:\\Program Files\\Microsoft VS Code\\Code.exe" "%V""

[HKEY_CLASSES_ROOT\\Directory\\ContextMenus\\VSCode\\shell\\openwsl\\command] @="wsl.exe --cd "%V" code ." ; This will open the current folder WSL-side, and then run code from there

Result: Sample image

from: https://gist.github.com/mbartelsm/be2a8ea761e5358cd04e3777d107b186#file-vscode_context-reg

And this for 'Open with code in WSL' (open file in WSL):
Make a registry file (.reg), paste code and run:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT*\\shell\\VSCodeWsl] @="Open w&ith Code in WSL" "Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

[HKEY_CLASSES_ROOT*\\shell\\VSCodeWsl\\command] @="wsl.exe code "$(wslpath '%1')""

result: open-with-code-in-wsl sample

from: https://github.com/matuszykrafa/open-with-code-in-wsl

Combining Open with Code (WSL) for folder and Open with Code (WSL) for file .

Thanks to @Mogzol for solving the pop-up window.

Windows Registry Editor Version 5.00
; You may replace
; C:\\Program Files\\Microsoft VS Code\\Code.exe
; with 
; C:\\Users\\Your User Name\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe
; for correct VS Code icon


; Add the option for right-click on a folder
[HKEY_CLASSES_ROOT\Directory\shell\VSCodeWSL]
@="Open with Code (WSL)"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

[HKEY_CLASSES_ROOT\Directory\shell\VSCodeWSL\command]
@="mshta vbscript:Execute(\"CreateObject(\"\"Wscript.Shell\"\").Run(\"\"wsl.exe code \"\"\"\"$(wslpath '%V')\"\"\"\"\"\", 0, False)(window.close)\")"


; Add the option for right-click in the background of current folder
[HKEY_CLASSES_ROOT\Directory\Background\shell\VSCodeWSL]
@="Open with Code (WSL)"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\VSCodeWSL\command]
@="mshta vbscript:Execute(\"CreateObject(\"\"Wscript.Shell\"\").Run(\"\"wsl.exe code \"\"\"\"$(wslpath '%V')\"\"\"\"\"\", 0, False)(window.close)\")"


; Add the option for right-click on a file
[HKEY_CLASSES_ROOT\*\shell\VSCodeWSL]
@="Open with Code (WSL)"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"

[HKEY_CLASSES_ROOT\*\shell\VSCodeWSL\command]
@="mshta vbscript:Execute(\"CreateObject(\"\"Wscript.Shell\"\").Run(\"\"wsl.exe code \"\"\"\"$(wslpath '%1')\"\"\"\"\"\", 0, False)(window. Close)\")"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM