使用 PowerShelll 将 Microsoft Edge 设置为默认浏览器

Zen*_*inツ 3 browser windows powershell microsoft-edge

我正在编写一个脚本,将默认浏览器更改为 Microsoft Edge,我已经这样做了:

function Set-DefaultBrowser {
  Add-Type -AssemblyName 'System.Windows.Forms'
  Start-Process $env:windir\system32\control.exe -LoadUserProfile -Wait -ArgumentList '/name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=MSEdgeHTM'
  Sleep 10
  [System.Windows.Forms.SendKeys]::SendWait("{TAB}{TAB}{TAB}{TAB}{TAB} {ENTER}{ENTER} ")
}
Set-DefaultBrowser
Run Code Online (Sandbox Code Playgroud)

但我不喜欢一个人打开菜单,我想做的事情而不像那样显示,可以这样做吗?

小智 5

我的建议是设置控制默认浏览器的注册表键。这是一个帖子的链接,展示了如何使用 Chrome 进行此操作

https://itectec.com/superuser/cmd-command-to-set-chrome-as-default-browser-windows-10/

您会注意到所需的命令,但将应用程序名称更改为 Edge 的名称

Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice' -Name ProgId -Value 'ChromeHTML'

Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice' -Name ProgId -Value 'ChromeHTML'
Run Code Online (Sandbox Code Playgroud)