Last active
          June 14, 2020 09:20 
        
      - 
      
- 
        Save FriedrichWeinmann/0b603370ec7bc7ab677908e6aed4a504 to your computer and use it in GitHub Desktop. 
    Register explorer shell extensions
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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