Windows注册表中对代理设置的更改无效

时间:2017-07-28 10:29:57

标签: windows powershell proxy registry

在一天中我经常需要打开和关闭"使用自动配置脚本"代理设置中的选项,用于访问否则被阻止的Web目标,反之亦然。换句话说,这个复选框:

enter image description here

我发现它更改了AutoConfigURL中的HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings属性。启用复选框后,该属性将设置为配置脚本URL,此时将删除该属性。所以我写了一个简单的PowerShell脚本来完成这项工作:

$regKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$propertyName = "AutoConfigURL"
$configurationScript = "http://example.com/config.dat"

$proxyStatus = (Get-ItemProperty -Path $regKey -ErrorAction SilentlyContinue).$propertyName

If ([string]::IsNullOrEmpty($proxyStatus)) {
    Set-ItemProperty -Path $regKey -Name $propertyName -Value $configurationScript
} Else {
    Remove-ItemProperty -Path $regKey -Name $propertyName
}

它以我需要的方式更改注册表,但是这些更改没有任何效果。我需要在Internet属性/ Connections下打开LAN设置窗口,然后才更改我的代理设置(我甚至不需要按OK或取消按钮,只需打开窗口)。

在更改注册表以应用更改后,是否还应执行其他命令?

1 个答案:

答案 0 :(得分:0)

我在下面的Powershell脚本(这是写得很好的脚本)中找到了您问题的答案。

https://github.com/majkinetor/posh/blob/master/MM_Network/Update-Proxy.ps1

此脚本实际上强制/刷新Internet设置。上面的脚本引用了msdn论坛,其中提到了C#解决方案。

https://social.msdn.microsoft.com/Forums/vstudio/en-US/19517edf-8348-438a-a3da-5fbe7a46b61a/how-to-change-global-windows-proxy-using-c-net-with-immediate-effect?forum=csharpgeneral