IE Enable/Disable Proxy Settings via Registry
The problem is that IE won't reset the proxy settings until it either
- closes, or
- has its configuration refreshed.
Below is the code that I've used to get this working:
function Refresh-System{ $signature = @'[DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);'@$INTERNET_OPTION_SETTINGS_CHANGED = 39$INTERNET_OPTION_REFRESH = 37$type = Add-Type -MemberDefinition $signature -Name wininet -Namespace pinvoke -PassThru$a = $type::InternetSetOption(0, $INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)$b = $type::InternetSetOption(0, $INTERNET_OPTION_REFRESH, 0, 0)return $a -and $b}
modifying the proxy value under
[HKEY_USERS\<your SID>\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
doesnt need to restart ie
I know this is an old question, however here is a simple one-liner to switch it on or off depending on its current state:
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value (-not ([bool](get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable).proxyenable))