Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to toggle proxy on and off as quick as possible.

We can use IE Proxy Toggle is is virus-free scanned to do this but I'm looking for a built-in command-line for it.

What is the command line for that?

ps

Currently I have to do it manually as below snapshot.

enter image description here

share|improve this question
    
was the "ps" a subliminal request for a PowerShell Script? – G Koe Feb 21 '14 at 6:01
    
You could also do this with an AutoHotKey script: autohotkey.com – G Koe Feb 21 '14 at 6:04
    
Thanks @GKoe. How to use AutoHotKey and/or PowerShell Script to do this? – Nam G VU Feb 21 '14 at 6:44
    
Please consider the Autohotkey tutorial and the keystrokes that would be required to do the functions that you are asking for. autohotkey.com/docs/Tutorial.htm – G Koe Feb 21 '14 at 6:49
    
Great post on powershell usage: stackoverflow.com/questions/2035193/… – G Koe Feb 21 '14 at 6:51

I tested this script with IE10 on windows 8 and the author tested it with Internet Explorer 11 on Windows 8.1, but I think that is should work with previous versions too… It was copied from here

remember that after executing the script, Internet Explorer must be restarted.

# This function toggle between the following Internet Explorer Settings 
# Explicit Proxy Disabled and automatically detect proxy set to ON 
# Explicit proxy Enabled and automatically detect proxy set to OFF

#provide your proxy here 
$proxyServerToDefine = "99.99.99.99:80"

function Set-AutomaticallyDetectProxySettings ($enable) 
{ 
    # Read connection settings from Internet Explorer. 
    $regKeyPath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\" 
    $conSet = $(Get-ItemProperty $regKeyPath).DefaultConnectionSettings 

    # Index into DefaultConnectionSettings where the relevant flag resides. 
    $flagIndex = 8 

    # Bit inside the relevant flag which indicates whether or not to enable automatically detect proxy settings. 
    $autoProxyFlag = 8 

    if ($enable) 
    { 
         if ($($conSet[$flagIndex] -band $autoProxyFlag) -eq $autoProxyFlag) 
        { 
        } 
        else 
        { 
            Write-Host "Enabling 'Automatically detect proxy settings'." 
             $conSet[$flagIndex] = $conSet[$flagIndex] -bor $autoProxyFlag 
            $conSet[4]++ 
            Set-ItemProperty -Path $regKeyPath -Name DefaultConnectionSettings -Value $conSet 
         } 
    } 
    else 
    { 
        if ($($conSet[$flagIndex] -band $autoProxyFlag) -eq $autoProxyFlag) 
        { 
            # 'Automatically detect proxy settings' was enabled, adding one disables it. 
            Write-Host "Disabling 'Automatically detect proxy settings'." 
            $mask = -bnot $autoProxyFlag 
             $conSet[$flagIndex] = $conSet[$flagIndex] -band $mask 
            $conSet[4]++ 
            Set-ItemProperty -Path $regKeyPath -Name DefaultConnectionSettings -Value $conSet 
        } 
    }

     $conSet = $(Get-ItemProperty $regKeyPath).DefaultConnectionSettings 
        if ($($conSet[$flagIndex] -band $autoProxyFlag) -ne $autoProxyFlag) 
        { 
            Write-Host "'Automatically detect proxy settings' is disabled." 
        } 
         else 
        { 
            Write-Host "'Automatically detect proxy settings' is enabled." 
        } 
}

$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" 
$proxyServer = "" 
Write-Host "Retrieve the proxy server ..." 
$proxyServer = Get-ItemProperty -path $regKey ProxyServer -ErrorAction SilentlyContinue 
Write-Host $proxyServer 
if([string]::IsNullOrEmpty($proxyServer)) 
{ 
    Write-Host "Proxy is actually disabled" 
    Set-AutomaticallyDetectProxySettings ($false) 

    Set-ItemProperty -path $regKey ProxyEnable -value 1 
    Set-ItemProperty -path $regKey ProxyServer -value $proxyServerToDefine 
    Write-Host "Proxy is now enabled" 
} 
else 
{ 
    Write-Host "Proxy is actually enabled" 
    Set-AutomaticallyDetectProxySettings ($true)

    Set-ItemProperty -path $regKey ProxyEnable -value 0 
    Remove-ItemProperty -path $regKey -name ProxyServer 
    Write-Host "Proxy is now disabled" 
}
share|improve this answer
    
This seems cool. How would we use this script @G Koe? – Nam G VU Feb 21 '14 at 6:38
1  
Great post on powershell usage: stackoverflow.com/questions/2035193/… – G Koe Feb 21 '14 at 6:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .