1

Windows 7 (64-bit) Disable Proxy via cmd - and put in effect?

I have found the correct registry key to change, and have code to change it.

reg add    "HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /f /v ProxyEnable /t REG_DWORD /d 0

Found via

gpresults /h "%userprofile%\desktop\RSPO.html"

Running the 'reg add' does change the reg key, same key that changes, when I open IE (as admin) and turn off the LAN proxy settings manually.

However, when I do it manually, the desired effect happens - I no longer have proxy issues. But via my cmd script, the key changes but I still have proxy issues. When I open the LAN proxy settings in IE, it's still Enabled.

How do I change the reg key and put it into effect?

Tried changing a bunch of registry keys...

Current script...

reg add "HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /f /v ProxyEnable /t REG_DWORD /d 0
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /f /v ProxyEnable /t REG_DWORD /d 0

reg add "HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /f /v ProxyEnable /t REG_DWORD /d 0
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /f /v ProxyEnable /t REG_DWORD /d 0
mrdnk
  • 111

4 Answers4

2

Unfortunately, there is no easy way. As you’ve noticed, you’re missing the magic “read those settings now” command:

InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, NULL)
InternetSetOption(NULL, INTERNET_OPTION_REFRESH, NULL, NULL)

Of course, you can’t just call a C function from cmd. There is, however, a (relatively) viable way to do it with PowerShell:

function Reload-InternetOptions
{
  $signature = @'
[DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int
dwOption, IntPtr lpBuffer, int dwBufferLength);
'@
  $interopHelper = Add-Type -MemberDefinition $signature -Name MyInteropHelper -PassThru

  $INTERNET_OPTION_SETTINGS_CHANGED = 39
  $INTERNET_OPTION_REFRESH = 37

  $result1 = $interopHelper::InternetSetOption(0, $INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
  $result2 = $interopHelper::InternetSetOption(0, $INTERNET_OPTION_REFRESH, 0, 0)

  $result1 -and $result2
}

Simply invoke it like this: Reload-InternetOptions. It will return True when successful.

Please note that this method dynamically creates some stuff each time you run it. It cannot be unloaded by PowerShell and will keep accumulating until you quit the PowerShell process that ran the method.

user219095
  • 65,551
0

I had the same issue when enabling/disabling a proxy using a vbs script.

I just added this:

Shell.run "ms-settings:network-proxy"

WScript.Sleep 1000

Shell.Run "taskkill /f /im SystemSettings.exe", , True

it opens the proxy settings, waits 1 second and then closes it. This will ensure that your proxy changes are working.

0

I have created simple CLI tool which force reload IE proxy settings. It calls WININET.DLL InternetSetOption function.

Download it from here: https://gofile.io/?c=ol4zE7

Tested on W7 and W10.

0

The IE settings are per-user, so I think you're just targeting the wrong Registry key.

For example, to turn our proxy check-box off domain-wide, we use a login script to disable it here:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable