Skip to content

Instantly share code, notes, and snippets.

@FriedrichWeinmann
Last active June 14, 2020 09:20
Show Gist options
  • Save FriedrichWeinmann/0b603370ec7bc7ab677908e6aed4a504 to your computer and use it in GitHub Desktop.
Save FriedrichWeinmann/0b603370ec7bc7ab677908e6aed4a504 to your computer and use it in GitHub Desktop.
Register explorer shell extensions
function Register-ShellExtension {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Name,
[Parameter(Mandatory = $true)]
[string]
$Text,
[Parameter(Mandatory = $true)]
[string]
$Command,
[Parameter(Mandatory = $true)]
[ArgumentCompleter({ 'Directory', '*' })]
[string]
$Extension,
[string]
$Icon
)
$drive = New-PSDrive -Name "HKCR_TEMP" -PSProvider Registry -Root 'HKEY_CLASSES_ROOT\'
$shellFolder = New-Item "HKCR_TEMP:\$Extension\shell\$Name" -Force
Set-ItemProperty -Path $shellFolder.PSPath -Name '(default)' -Value $Text
$commandFolder = New-Item -Path $shellFolder.PSPath -Name 'command'
Set-ItemProperty -Path $commandFolder.PSPath -Name '(default)' -Value $Command
$drive | Remove-PSDrive
}
Register-ShellExtension -Name vscode -Text 'Open in VSCode' -Command "`"$env:LOCALAPPDATA\Programs\Microsoft VS Code\bin\code.cmd`" -n `"%1`"" -Extension Directory
<#
Note: Path to code.cmd may vary.
To find it, you can run this as long as it was added to %Path%:
Get-Command code | Select-Object -ExpandProperty Source
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment