如何使用 powershell 应用更改的代理设置 (AutoConfigURL)
How to apply changed proxy settings (AutoConfigURL) with powershell
我的代理是使用 IE LAN 设置对话框中的 "automatic configuration script" 选项配置的。为了切换此设置,我编写了以下 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
函数。
我的代理是使用 IE LAN 设置对话框中的 "automatic configuration script" 选项配置的。为了切换此设置,我编写了以下 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
函数。