Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply changed proxy settings (AutoConfigURL) with powershell

My proxy is configured using the "automatic configuration script" option in the LAN settings dialog in IE. In order to toggle this settings I have written the following powershell script:

$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"
}

The script seems to work as the values have changed in IE's LAN settings dialog after having executed the script. But they seem not to be applied in IE and other applications using the system wide settings. Only when I click on the OK button in the LAN settings dialog the updated values get applied.

Is there a way to apply the changed settings automatically using powershell?

like image 238
siom Avatar asked Apr 14 '15 09:04

siom


1 Answers

You need to notify the system about update. Check out my proxy module which doesn't handle autoconfig but the principle is the same

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

See refresh-system function.

like image 175
majkinetor Avatar answered Nov 15 '22 03:11

majkinetor