我的代理是使用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自动应用更改的设置?
您需要通知系统有关更新。看看我的代理模块,它不处理自动配置,但是原理是一样的
https://github.com/majkinetor/posh/blob/master/MM_Network/Update-Proxy.ps1
参见refresh-system
功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句