无法将Chrome设置为Powershell的默认浏览器

Cha*_*ell 2 powershell

我正在运行以下powershell命令

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

不幸的是,当我运行它时,我收到以下错误消息.

cmd.exe:[1396:2128:0708/153347:错误:gpu_info_collector_win.cc(98)]无法检索有效的WinSAT评估.在行: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:错误:shell_integration_win.cc(200)] Chrome无法设置为默认浏览器.

可能导致此错误的原因是什么?我意识到有各种方法来执行命令,但最重要的是,使用--make-default-browser交换机执行Chrome 是失败的.

Tec*_*pud 7

poshcode上尝试此链接,您可以使用该链接在Chrome,Firefox,Internet Explorer,Opera和Safari之间切换.我在版本上测试了所有5个浏览器......

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

PoShCode片段中的代码如下......

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
Run Code Online (Sandbox Code Playgroud)

  • 我刚刚在 Windows 10 中尝试过此操作,但没有成功。它刚刚触发了以下 Windows 错误:“某个应用导致您的默认浏览器设置出现问题,因此已重置为 Microsoft Edge。” (5认同)
  • @Sam,这是一个众所周知的Windows 10问题.请参阅:http://www.winhelponline.com/blog/windows-10-resetting-file-associations/或http://winaero.com/blog/prevent-windows-10-from-resetting-your-default-apps / (2认同)

Ben*_*ard 1

以下对我有用:

$chromePath = "${Env:ProgramFiles(x86)}\Google\Chrome\Application\" 
$chromeApp = "chrome.exe"
$chromeCommandArgs = "--make-default-browser"
& "$chromePath$chromeApp" $chromeCommandArgs
Run Code Online (Sandbox Code Playgroud)