Windows 7 Disable Proxy via cmd - and put in effect

25,751

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.

Share:
25,751
mrdnk
Author by

mrdnk

Updated on September 18, 2022

Comments

  • mrdnk
    mrdnk over 1 year

    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
      mrdnk about 10 years
      I'm running cmd as admin. After running the script I get "The operation completed successfully". And the registry key has changed.
    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 about 10 years
      Can you edit your question to include the actual registry location you're changing?
    • mrdnk
      mrdnk about 10 years
      There you go, sorry - had Stack Exchange logged in on different machine.
    • JSanchez
      JSanchez about 10 years
      Not sure if you've noticed, but you have REG_DWARD instead of REG_DWORD Could that be it?
    • mrdnk
      mrdnk about 10 years
      Just a typo on Superuser, have actually pasted in the whole cmd now.
    • JSanchez
      JSanchez about 10 years
      @mrdnk: Try to escape the backslashes in your script using the caret ^ symbol. Or use double backslashes. See if that solves your issue.
    • JSanchez
      JSanchez about 10 years
      For reg, it is double backslashes: ss64.com/nt/syntax-esc.html
    • mrdnk
      mrdnk about 10 years
      it's in quotes, and it is changing the value.
    • JSanchez
      JSanchez about 10 years
      @mrdnk: You are running a 64-bit OS. Just realized that. ovidiupl.wordpress.com/2008/07/11/…
    • mrdnk
      mrdnk about 10 years
      Interesting read. Still no joy, but it gives me something to look into a bit deeper.
    • Butzke
      Butzke over 8 years
  • mrdnk
    mrdnk about 10 years
    That's what I initally went for by I found this in the gpresults ... Policy Setting Winning GPO Make proxy settings per-machine (rather than per-user) Enabled TMG Proxy Settings Policy
  • mrdnk
    mrdnk about 10 years
    And... Registry item (Key path: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\Cu‌​rrentVersion\Interne‌​t Settings, Value name: ProxyEnable)
  • Ƭᴇcʜιᴇ007
    Ƭᴇcʜιᴇ007 about 10 years
    Ok, and as you say, it doesn't work. ;) Does it work as you want if you use the HKCU key instead?
  • mrdnk
    mrdnk about 10 years
    Tried changing a bunch of keys, see edit.
  • Th1sD0t
    Th1sD0t about 4 years
    Out of curiosity, how do you know that this event is needed to make the changes take effect?
  • Daniel B
    Daniel B about 4 years
    @C4p741nZ Do you mean how to find out stuff like this? In the old days, you’d have to check the documentation. Nowadays you can just use Google. The trick is of course to find the right search terms.