如何在Google Chrome浏览器中设置起始页?

时间:2018-10-31 10:32:03

标签: powershell powershell-v4.0 chocolatey

我想使用PowerShell脚本设置Google Chrome的默认启动页面。 不幸的是,它无法按预期工作。

如果我通过安装文件安装Chrome浏览器,则可以正常运行。 但是,如果我通过Chocolatey安装了Google Chrome浏览器,我的脚本将无法正常工作。

这是我已经拥有的:

$policyexists = Test-Path HKLM:\SOFTWARE\Policies\Google\Chrome
$policyexistshome = Test-Path HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs
$regKeysetup = "HKLM:\SOFTWARE\Policies\Google\Chrome"
$regKeyhome = "HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs"
$url = "https://www.google.com"

if ($policyexists -eq $false) {
    New-Item -path HKLM:\SOFTWARE\Policies\Google
    New-Item -path HKLM:\SOFTWARE\Policies\Google\Chrome
    New-ItemProperty -path $regKeysetup -Name RestoreOnStartup -PropertyType Dword -Value 4
    New-ItemProperty -path $regKeysetup -Name HomepageLocation -PropertyType String -Value $url
    New-ItemProperty -path $regKeysetup -Name HomepageIsNewTabPage -PropertyType DWord -Value 0
} else {
    Set-ItemProperty -Path $regKeysetup -Name RestoreOnStartup -Value 4
    Set-ItemProperty -Path $regKeysetup -Name HomepageLocation -Value $url
    Set-ItemProperty -Path $regKeysetup -Name HomepageIsNewTabPage -Value 0
}

if ($policyexistshome -eq $false) {
    New-Item -path HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs
    New-ItemProperty -path $regKeyhome -Name 1 -PropertyType String -Value $url
} else {
    Set-ItemProperty -Path $regKeyhome -Name 1 -Value $url
}

0 个答案:

没有答案