Skip to content

Instantly share code, notes, and snippets.

@Makeshift
Last active December 30, 2020 22:27
Show Gist options
  • Select an option

  • Save Makeshift/2a75d2ea5e27f1380e4419914614fd53 to your computer and use it in GitHub Desktop.

Select an option

Save Makeshift/2a75d2ea5e27f1380e4419914614fd53 to your computer and use it in GitHub Desktop.
A reg file that modifies the "Open with Code" context menu to instead open with WSL VSCode
Windows Registry Editor Version 5.00
; The content of the hex below is as follows:
; C:\Windows\System32\wsl.exe bash -c "p='%V';p=\${p/W:/\\\\\\\\wsl$\\\\Ubuntu};echo Opening \$p ...;code \$(wslpath \$p)"
; %V contains the directory you right clicked in/on. This command uses wslpath to convert the Windows dir to a WSL dir, then
; uses 'code <dir>' to open it (assuming you have the remote VSCode command installed)
; The other bits relating to W: are specific to my needs, as I have \\wsl$\Ubuntu\ mounted as W:
; If you do the same, you will be able to 'Open with Code' on a WSL network mount
; Otherwise, it will still work as intended on Windows filepaths.
[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\VSCode\command]
""=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,77,00,73,00,6c,00,2e,00,65,00,78,00,65,00,20,00,62,00,61,00,73,00,68,00,20,00,2d,00,63,00,20,00,22,00,70,00,3d,00,27,00,25,00,56,00,27,00,3b,00,70,00,3d,00,5c,00,24,00,7b,00,70,00,2f,00,57,00,3a,00,2f,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,77,00,73,00,6c,00,24,00,5c,00,5c,00,5c,00,5c,00,55,00,62,00,75,00,6e,00,74,00,75,00,7d,00,3b,00,65,00,63,00,68,00,6f,00,20,00,4f,00,70,00,65,00,6e,00,69,00,6e,00,67,00,20,00,5c,00,24,00,70,00,20,00,2e,00,2e,00,2e,00,3b,00,63,00,6f,00,64,00,65,00,20,00,5c,00,24,00,28,00,77,00,73,00,6c,00,70,00,61,00,74,00,68,00,20,00,5c,00,24,00,70,00,29,00,22,00,00,00
[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\VSCode\command]
""=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,77,00,73,00,6c,00,2e,00,65,00,78,00,65,00,20,00,62,00,61,00,73,00,68,00,20,00,2d,00,63,00,20,00,22,00,70,00,3d,00,27,00,25,00,56,00,27,00,3b,00,70,00,3d,00,5c,00,24,00,7b,00,70,00,2f,00,57,00,3a,00,2f,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,77,00,73,00,6c,00,24,00,5c,00,5c,00,5c,00,5c,00,55,00,62,00,75,00,6e,00,74,00,75,00,7d,00,3b,00,65,00,63,00,68,00,6f,00,20,00,4f,00,70,00,65,00,6e,00,69,00,6e,00,67,00,20,00,5c,00,24,00,70,00,20,00,2e,00,2e,00,2e,00,3b,00,63,00,6f,00,64,00,65,00,20,00,5c,00,24,00,28,00,77,00,73,00,6c,00,70,00,61,00,74,00,68,00,20,00,5c,00,24,00,70,00,29,00,22,00,00,00
[HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\VSCode\command]
""=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,77,00,73,00,6c,00,2e,00,65,00,78,00,65,00,20,00,62,00,61,00,73,00,68,00,20,00,2d,00,63,00,20,00,22,00,70,00,3d,00,27,00,25,00,56,00,27,00,3b,00,70,00,3d,00,5c,00,24,00,7b,00,70,00,2f,00,57,00,3a,00,2f,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,5c,00,77,00,73,00,6c,00,24,00,5c,00,5c,00,5c,00,5c,00,55,00,62,00,75,00,6e,00,74,00,75,00,7d,00,3b,00,65,00,63,00,68,00,6f,00,20,00,4f,00,70,00,65,00,6e,00,69,00,6e,00,67,00,20,00,5c,00,24,00,70,00,20,00,2e,00,2e,00,2e,00,3b,00,63,00,6f,00,64,00,65,00,20,00,5c,00,24,00,28,00,77,00,73,00,6c,00,70,00,61,00,74,00,68,00,20,00,5c,00,24,00,70,00,29,00,22,00,00,00
; Run this script with: regini set_key_permissions.txt
; It sets the keys to read-only so vscode updates doesn't mess with them
; Specifically:
; 2 - Administrators read access (replaces the current write access)
; 5 - Creator full access (your user)
; 8 - World read access
; 19 - System read access (since I think it has write by default?)
; Note: While this appears to work, I haven't extensively tested it
HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\VSCode\command [2 5 8 19]
HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\VSCode\command [2 5 8 19]
HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\VSCode\command [2 5 8 19]
@Makeshift
Copy link
Copy Markdown
Author

Makeshift commented Dec 30, 2020

Note: This seems to need to be re-ran periodically, assuming after VSCode updates.

Edit: Added set_key_permissions.txt to be ran with regini which appears to resolve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment