ttaaoossuu
ttaaoossuu

Reputation: 7884

Changes to proxy settings in Windows registry have no effect

During the course of day I often have to turn on and off "Use automatic configuration script" option in proxy settings to access web destinations that are otherwise blocked and vice versa. In other words, this checkbox:

enter image description here

I found that it changes AutoConfigURL property in HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings. When checkbox is on, the property is set to configuration script URL, when it's off the property is removed. So I wrote a simple PowerShell script to do the job:

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

It changes the registry the way I need, however these changes have no effect. I need to open the LAN settings window under Internet properties / Connections and only then my proxy settings are changed (I don't even need to press OK or Cancel buttons, just open the window).

Are there any additional commands that should be executed after making changes to the registry to apply changes?

Upvotes: 1

Views: 4393

Answers (1)

Venu
Venu

Reputation: 475

I found the answer to your question in the below Powershell script (It's a nicely written script).

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

This script actually forces/refreshes the internet settings. The above script refers to the msdn forum, where C# solution was mentioned.

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

Upvotes: 1

Related Questions