Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set Chrome as default browser from Powershell

Tags:

powershell

I'm running the following powershell commmand

$chromePath = "${Env:ProgramFiles(x86)}\Google\Chrome\Application\" 
$chromeApp = "chrome.exe"
$chromeCommandArgs = @('--make-default-browser')
Invoke-Expression “cmd.exe /C `"$chromePath$chromeApp`" $chromeCommandArgs”

Unfortunatley, when I run this, I get the following error message.

cmd.exe : [1396:2128:0708/153347:ERROR:gpu_info_collector_win.cc(98)] Can't retrieve a valid WinSAT assessment. At line:1 char:1 + cmd.exe /C "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --make- ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: ([1396:2128:0708...SAT assessment.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError

[1396:2128:0708/153347:ERROR:shell_integration_win.cc(200)] Chrome could not be set as default browser.

What could be causing this error? I realize there are various ways of executing the command, but the bottom line is that executing Chrome with the --make-default-browser switch is failing.

like image 721
Chase Florell Avatar asked Jul 08 '13 21:07

Chase Florell


1 Answers

Adapted from this archived poshcode user script, with which you can switch between Chrome, Firefox, Internet Explorer, Opera and Safari. Add the Set-DefaultBrowser function like this:

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
        }
    } 

}

Then invoke it with your desired browser like this:

Set-DefaultBrowser cr # cr|ff|ie|op|sa

And you can check that the correct values are set in the registry like this:

(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

I've tested with all 5 browsers with the following versions:

  • Chrome = 39
  • Firefox = 34
  • Internet Explorer = 11
  • Opera = 11
  • Safari = 5

Further Reading: How Does Your Browser Know that It’s Not The Default?

like image 116
TechSpud Avatar answered Sep 28 '22 19:09

TechSpud