如何使用powershell应用更改的代理设置(AutoConfigURL)

时间:2015-04-14 09:28:47

标签: internet-explorer powershell proxy

我的代理使用"自动配置脚本"进行配置。 IE中LAN设置对话框中的选项。为了切换这个设置,我编写了以下powershell脚本:

$proxyScript = 'http://example.com/files/wish.pac'
$debug = $TRUE
$currentValue = Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL -ErrorAction SilentlyContinue

if($debug)
{
    Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
}

if([string]::IsNullOrEmpty($currentValue))
{
    Write-Host "Proxy-AutoConfigURL is actually disabled"
    Set-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL -value $proxyScript
    Write-Host "Proxy-AutoConfigURL is enabled: " + $proxyScript
}
else
{
    Write-Host "Proxy-AutoConfigURL is actually enabled"
    Remove-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name AutoConfigURL
    Write-Host "Proxy-AutoConfigURL is disabled."
}

if($debug)
{
    Get-ItemProperty -Path HKCU:"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
}

在执行脚本后,IE的LAN设置对话框中的值已更改,因此脚本似乎正常工作。但它们似乎不适用于使用系统范围设置的IE和其他应用程序。只有当我单击LAN设置对话框中的确定按钮时,才会应用更新的值。

有没有办法使用PowerShell自动应用更改的设置?

1 个答案:

答案 0 :(得分:5)

您需要通知系统有关更新的信息。查看我的代理模块,它不处理autoconfig,但原理是相同的

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

请参阅refresh-system功能。