# encoding: ascii
# api: powershell
# title: Set-defaultBrowser
# description: With this function I can switch between Chrome, Firefox, IE, Opera and Safari as default browser. It is just a start. There might be some more registry keys to be changed
# version: 0.1
# type: function
# author: Andy Myatt
# license: CC0
# function: Set-DefaultBrowser
# x-poshcode-id: 5679
# x-archived: 2017-03-19T19:33:16
# x-published: 2017-01-09T11:37:00
#
#
function Set-DefaultBrowser
{
param($defaultBrowser)
$regKey = "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\{0}\UserChoice"
$regKeyFtp = $regKey -f 'ftp'
$regKeyHttp = $regKey -f 'http'
$regKeyHttps = $regKey -f 'https'
switch -Regex ($defaultBrowser.ToLower())
{
# Internet Explorer
'ie|internet|explorer' {
Set-ItemProperty $regKeyFtp -name ProgId IE.FTP
Set-ItemProperty $regKeyHttp -name ProgId IE.HTTP
Set-ItemProperty $regKeyHttps -name ProgId IE.HTTPS
break
}
# Firefox
'ff|firefox' {
Set-ItemProperty $regKeyFtp -name ProgId FirefoxURL
Set-ItemProperty $regKeyHttp -name ProgId FirefoxURL
Set-ItemProperty $regKeyHttps -name ProgId FirefoxURL
break
}
# Google Chrome
'cr|google|chrome' {
Set-ItemProperty $regKeyFtp -name ProgId ChromeHTML
Set-ItemProperty $regKeyHttp -name ProgId ChromeHTML
Set-ItemProperty $regKeyHttps -name ProgId ChromeHTML
break
}
# Safari
'sa*|apple' {
Set-ItemProperty $regKeyFtp -name ProgId SafariURL
Set-ItemProperty $regKeyHttp -name ProgId SafariURL
Set-ItemProperty $regKeyHttps -name ProgId SafariURL
break
}
# Opera
'op*' {
Set-ItemProperty $regKeyFtp -name ProgId Opera.Protocol
Set-ItemProperty $regKeyHttp -name ProgId Opera.Protocol
Set-ItemProperty $regKeyHttps -name ProgId Opera.Protocol
break
}
}
# thanks to http://newoldthing.wordpress.com/2007/03/23/how-does-your-browsers-know-that-its-not-the-default-browser/
<#
(Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ftp\UserChoice').ProgId
(Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice').ProgId
(Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice').ProgId
#>
}
# Set-DefaultBrowser cr
# Set-DefaultBrowser ff
# Set-DefaultBrowser ie
# Set-DefaultBrowser op
# Set-DefaultBrowser sa