Skip to content

Instantly share code, notes, and snippets.

@matt2005
Created June 30, 2015 12:15
Show Gist options
  • Save matt2005/e97eda1c78aa7e43e869 to your computer and use it in GitHub Desktop.
Save matt2005/e97eda1c78aa7e43e869 to your computer and use it in GitHub Desktop.
Remote Desktop URL Handler
#Enables use of RDP://servername to open in mstsc
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
Try {New-Item -Path HKCR:rdp -erroraction stop}
Catch {Remove-Item -Path HKCR:rdp -recurse -ErrorAction SilentlyContinue
New-Item -Path HKCR:rdp -ErrorAction SilentlyContinue}
Finally {$rdp=Get-childitem -Path HKCR:rdp}
Try {New-ItemProperty -LiteralPath HKCR:rdp -name '(Default)' -Value "URL:Remote Desktop Protocol <URL:Remote%20Desktop%20Protocol> " -erroraction stop}
Catch {Set-ItemProperty -LiteralPath HKCR:rdp -name '(Default)' -Value "URL:Remote Desktop Protocol <URL:Remote%20Desktop%20Protocol> " -ErrorAction SilentlyContinue}
Try {New-ItemProperty -LiteralPath HKCR:rdp -name 'EditFlags' -Type DWORD -Value "2" -erroraction stop}
Catch {Set-ItemProperty -LiteralPath HKCR:rdp -name 'EditFlags' -Type DWORD -Value "2" -ErrorAction SilentlyContinue}
Try {New-ItemProperty -LiteralPath HKCR:rdp -name 'URL Protocol' -Type String -Value "" -erroraction stop}
Catch {Set-ItemProperty -LiteralPath HKCR:rdp -name 'URL Protocol' -Type String -Value "" -ErrorAction SilentlyContinue}
Try {Get-Item -Path HKCR:rdp\shell\open\command -erroraction stop}
Catch {New-Item -Path HKCR:rdp\shell\open\command -force -erroraction stop}
Try {New-ItemProperty -LiteralPath HKCR:rdp\shell\open\command -name '(Default)' -Value 'cmd /V:ON /c setlocal && set url=%1 && set url=!url:rdp://=! && set url=!url:/=! && start mstsc.exe /v:!url!' -erroraction stop}
Catch {Set-ItemProperty -LiteralPath HKCR:rdp\shell\open\command -name '(Default)' -Value 'cmd /V:ON /c setlocal && set url=%1 && set url=!url:rdp://=! && set url=!url:/=! && start mstsc.exe /v:!url!' -ErrorAction SilentlyContinue}
Remove-PSDrive -Name HKCR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment