Skip to content

Instantly share code, notes, and snippets.

@mark05e
Last active May 16, 2024 16:37
Show Gist options
  • Save mark05e/cd2e8b9981b675cd8b5975ab34111d84 to your computer and use it in GitHub Desktop.
Save mark05e/cd2e8b9981b675cd8b5975ab34111d84 to your computer and use it in GitHub Desktop.
AHK Script with GUI to enable/disable proxy. Works on Win10 too!
; my_ie_proxy.ahk
;#################################################################################
; Enable/Disable IE Proxy with GUI
;#################################################################################
; ref: //autohotkey.com/board/topic/101854-switch-proxy-on-or-off/?p=634033
global AddressPort = "proxy.myproxyprovider.com:1234"
Gui, Add, Text, x20 cBlue, %AddressPort%
Gui, Add, Button, x26 y20 w100 h30 Gon , I'm at work
Gui, Add, Button, x26 y60 w100 h30 Goff , I'm at home
Gui, Show, x129 y99 h100 w154, Proxy Toggler
Return
on:
setproxy("ON")
ExitApp
return
off:
setproxy("OFF")
ExitApp
return
setproxy(state="")
{
if(state = "")
state = "ON"
if (state ="ON"){
RegWrite,REG_SZ,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyServer,%AddressPort%
RegWrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyEnable,1
}
else if (state="OFF"){
RegWrite,REG_SZ,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyServer,
RegWrite,REG_DWORD,HKCU,Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyEnable,0
}
dllcall("wininet\InternetSetOptionW","int","0","int","39","int","0","int","0")
dllcall("wininet\InternetSetOptionW","int","0","int","37","int","0","int","0")
Return
}
;----------------------------------------------------------
; Function RegRead
;----------------------------------------------------------
RegRead(RootKey, SubKey, ValueName = "") {
RegRead, v, %RootKey%, %SubKey%, %ValueName%
Return, v
}
GuiClose:
ExitApp
@erbanku
Copy link

erbanku commented May 15, 2024

This works fine.
(Written by ChatGPT)

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Toggle Proxy
^!p::  ; Ctrl+Alt+P as the hotkey.
ToggleProxy()
return

ToggleProxy() {
    ; Access the registry key where proxy settings are stored.
    RegRead, ProxyEnable, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Internet Settings, ProxyEnable
    
    ; Check if the proxy is currently enabled (ProxyEnable = 1).
    if (ProxyEnable = 1) {
        ; Proxy is enabled, so disable it.
        RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Internet Settings, ProxyEnable, 0
        Tooltip, Proxy disabled.
    } else {
        ; Proxy is disabled, so enable it.
        RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Internet Settings, ProxyEnable, 1
        Tooltip, Proxy enabled.
    }

    ; Refresh Internet settings to apply changes.
    DllCall("Wininet.dll\InternetSetOptionW", UInt, 0, UInt, 39, UInt, 0, UInt, 0)  ; INTERNET_OPTION_SETTINGS_CHANGED
    DllCall("Wininet.dll\InternetSetOptionW", UInt, 0, UInt, 37, UInt, 0, UInt, 0)  ; INTERNET_OPTION_REFRESH

    ; Show a notification for 1 second.
    SetTimer, RemoveTooltip, 1000  ; Remove the tooltip after 1 second.
    return
}

RemoveTooltip:
    SetTimer, RemoveTooltip, Off
    Tooltip
return

@mark05e
Copy link
Author

mark05e commented May 16, 2024

Thank you for sharing @erbanku

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment