Enable/Disable /Change IE Proxy by script/programmatically

Ok. You know the drill, you need to use the company’s proxy server at work and at home you don’t need a proxy server.(or you use another one)

Well, do you really want to open up IE and go into Tools->Internet Options->Connections->LAN Settings->Proxy Server to change the address or disable/enable it?

(You can actually open Internet Options from Control Panel without opening up IE, but anyway, it still is a long process.)

As everything useful is done in Registry in Windows, we again have some registry scripts.

To disable proxy:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000000

To enable proxy:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000001

To change proxy:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"MigrateProxy"=dword:00000001
"ProxyEnable"=dword:00000001
"ProxyHttp1.1"=dword:00000000
"ProxyServer"="http://ProxyServername:80"
"ProxyOverride"="<local>"

Copy these to a .reg file and double click on them to do the trick.  The good part of doing it this way is that it works on every IE version(well, I haven’t tried any IE lower than IE6 :) and it is able to change it without even opening up anything.

You can actually do more by making a VBS script or whatever to get the current local ip address and check if it is an address in your home network or work network, and do the necessary action automatically.

About these ads

10 Comments

  1. Tommy Petersen said,

    November 23, 2009 at 3:30 pm

    It tells me it needs a binary registry file when I double click it.
    The full error is:
    Cannot import c:\prxydisable.reg: The specified file is not a registry script. You can only import binary registry files from within the registry editor.

    • Tommy Petersen said,

      November 23, 2009 at 3:58 pm

      Sorry, it is working as described.
      I just can’t even cut an paste correctly.

  2. mohammaddesign said,

    December 29, 2009 at 5:41 pm

    don’t run by double click :(

  3. mohammaddesign said,

    December 29, 2009 at 5:43 pm

    please help me to do it correctly :)

  4. Ozan Safi said,

    January 11, 2010 at 8:48 am

    Hi Mohammad, sorry for the late reply. Have you been able to solve your problem, or should I attempt to help you?

  5. Kyle said,

    February 17, 2010 at 3:14 am

    I was able to create these registry keys and even assigned them to shortcut keys. My only problem is that when the registry values are changed, the enabled or disabled proxy setting only takes effect when you invoke another IE session. Do you know any way for it to force the current session to accept the changes as well? If you go through the clicking steps it takes effect immediately. I only ask because I work at a place where I frequently go back/forth between proxy server and no proxy server many times throughout the day. I also use IE7 and just creating a new tab doesn’t do the trick either…any suggestions?

    Thanks for the tip by the way, I was looking for something exactly like this.

  6. Heather said,

    September 3, 2010 at 5:34 pm

    Thanks so much, this was very helpful!

  7. minhthanh9x said,

    January 16, 2011 at 4:41 pm

    Windows XP : OK
    Windows 7 : :(

  8. Dan said,

    August 6, 2011 at 8:04 am

    I’ve developed a way to do it silently, immediately and automatically using our friend “PowerShell”. Here’s the syntax:
    POWERSHELL.EXE -ExecutionPolicy Bypass -WindowStyle Hidden “proxytoggle.ps1″ [disable]

    Here’s the code:
    - – - proxytoggle.ps1 – - -

    # Process command line parameter (if present).
    [bool] $DISABLE_PROXY = $false;
    foreach ($param in $MyInvocation.UnboundArguments) {
    if ($param -like ‘disable’) { $DISABLE_PROXY = $true; }
    }

    # Apply/refresh the organization’s default proxy settings.
    [string] $proxyServer = ‘XXX.XXX.XXX.XXX’;
    [string] $proxyOverride = ‘*.local;192.168.*;’;
    [int] $migrateProxy = 1;
    [int] $proxyHttp11 = 1;

    REG ADD “””HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings”” /v “”ProxyServer”” /t REG_SZ /d “”$proxyServer”” /f” | Out-Null;
    REG ADD “””HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings”” /v “”ProxyOverride”” /t REG_SZ /d “”$proxyOverride”” /f” | Out-Null;
    REG ADD “””HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings”” /v “”MigrateProxy”” /t REG_DWORD /d $migrateProxy /f” | Out-Null;
    REG ADD “””HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings”” /v “”ProxyHttp1.1″” /t REG_DWORD /d $proxyHttp11 /f” | Out-Null;

    function Start-HiddenIEProcess () {
    [object] $ieProcess = $null;

    # Launch Internet Explorer (use 32-bit version only) in a hidden window.
    if (Test-Path “$env:PROGRAMFILES(X86)\Internet Explorer\iexplore.exe”) {
    $ieProcess = Start-Process -Passthru -FilePath “$env:PROGRAMFILES(X86)\Internet Explorer\iexplore.exe” -WindowStyle Hidden -ErrorAction SilentlyContinue;
    } else {
    $ieProcess = Start-Process -Passthru -FilePath “$env:PROGRAMFILES\Internet Explorer\iexplore.exe” -WindowStyle Hidden;
    }
    # Wait for Internet Explorer to load fully.
    [int] $count = 10;
    do {
    if (($ieProcess.WaitForInputIdle())) {
    $waiting = $false; # IE is ready.
    $count = 0;
    } else {
    Start-Sleep 1; # Sleep for another second.
    $count–; # Decrement wait counter.
    }
    } while ($waiting -or ($count -gt 0));

    # Check to see if our new process exists.
    if ((Get-Process -Name iexplore -ErrorAction SilentlyContinue)) {
    return $true;
    } else {
    return $false;
    }
    } # END

    function Set-ProxyState ([bool] $disable) {
    # Kill existing IE processes.
    Stop-Process -Name iexplore -Force -ErrorAction SilentlyContinue;

    # Toggle proxy state.
    if ($disable) {
    Write-Host ‘DISABLING user”s proxy settings…’;
    REG ADD ‘”HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v “ProxyEnable” /t REG_DWORD /d 0 /f’ | Out-Null; # Disable proxy.
    } else {
    Write-Host ‘ENABLING user”s proxy settings…’;
    REG ADD ‘”HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v “ProxyEnable” /t REG_DWORD /d 1 /f’ | Out-Null; # Enable proxy.
    }

    # Start a new/hidden IE process temporarily.
    Start-HiddenIEProcess;

    # Kill existing IE processes.
    Stop-Process -Name iexplore -Force -ErrorAction SilentlyContinue;

    Write-Host ‘[DONE]‘;

    return $null;
    } # END

    # Toggle the user’s proxy settings.
    $null = Set-ProxyState $DISABLE_PROXY;

  9. jobin said,

    November 1, 2011 at 6:25 pm

    @Dan

    Great Job. Can you pls tell how to make it working? I run the script but no changes happened


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: