Skip to content

Instantly share code, notes, and snippets.

@Svetomech
Created August 28, 2017 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Svetomech/3c69a0345897c5de4cbc0b2d78180348 to your computer and use it in GitHub Desktop.
Save Svetomech/3c69a0345897c5de4cbc0b2d78180348 to your computer and use it in GitHub Desktop.
Adds Visual Studio Code menu entries for ALL users (which the installer won't do, even though it requires admin rights)
## Configure Open with VSCode Context Menu ##
# Configure VSCode location
$vscodeLoc = [Environment]::ExpandEnvironmentVariables("%PROGRAMFILES%") + '\Microsoft VS Code\Code.exe'
$regHive = 'HKLM:' # Change this to 'HKCU:' if you only want this for your current user
# Configure Open with VSCode for files
New-Item -Path "$regHive\SOFTWARE\Classes\*\shell\VSCode"
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\*\shell\VSCode" -Name '(Default)' -Type ExpandString -Value 'Open with VSCode'
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\*\shell\VSCode" -Name 'Icon' -Type ExpandString -Value "$vscodeLoc"
New-Item -Path "$regHive\SOFTWARE\Classes\*\shell\VSCode\command"
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\*\shell\VSCode\command" -Name '(Default)' -Type ExpandString -Value "`"$vscodeLoc`" `"%1`""
# Configure Open with VSCode for Directories
New-Item -Path "$regHive\SOFTWARE\Classes\directory\shell\VSCode"
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\directory\shell\VSCode" -Name '(Default)' -Type ExpandString -Value 'Open with VSCode'
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\directory\shell\VSCode" -Name 'Icon' -Type ExpandString -Value "$vscodeLoc"
New-Item -Path "$regHive\SOFTWARE\Classes\directory\shell\VSCode\command"
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\directory\shell\VSCode\command" -Name '(Default)' -Type ExpandString -Value "`"$vscodeLoc`" `"%V`""
# Configure Open with VSCode for Directories while inside the directory (right-click on empty space)
New-Item -Path "$regHive\SOFTWARE\Classes\directory\background\shell\VSCode"
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\directory\background\shell\VSCode" -Name '(Default)' -Type ExpandString -Value 'Open with VSCode'
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\directory\background\shell\VSCode" -Name 'Icon' -Type ExpandString -Value "$vscodeLoc"
New-Item -Path "$regHive\SOFTWARE\Classes\directory\background\shell\VSCode\command"
Set-ItemProperty -LiteralPath "$regHive\SOFTWARE\Classes\directory\background\shell\VSCode\command" -Name '(Default)' -Type ExpandString -Value "`"$vscodeLoc`" `"%V`""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment