Sign in to follow this  
Followers 0
jquonce

IE Proxy Changer - error

2 posts in this topic

Our company has disabled proxy server changes via group policy, but it can still be changed via registry, so I have the following code but I am getting an error no since upgrade to IE 7 and IE 8. I am kinda lost on it right now and thought maybe some fresh eyes might be able to see something that I am mising. Everything still works except when you hit the Apply button. What I wanted it to orginally do it apply and exit the program but I was having trouble with that as well.

Thanks for taking the time to look.

#Region ; Changelog
;~ 1.3 James Q - Modified Code and GUI for Laptop USERS.
;  1.2 Rajesh V R - GUI Modification, Added events to update Checkbox Statuses (Bypass Localserver is pending)
;~ 1.1 Rajesh V R - just tidied code 
;~ 1.0 John_W - Orignal version

#EndRegion

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Global $radHome, $radGehl, $guiProxy, $proxyAutoSettings, $IEVersion, $chkBxAutoDetect, $chkBxAutoConfig, $chkBxProxyLan, $inpProxyServer
Global $inpPort, $chkBxBypass, $inpBypassAdd, $inpAutoConfig, $proxyAutoTemp
Global $CONSTKEYPROXY = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Global $CONSTKEYHOME = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main"
Global $CONSTKEYAUTO = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
Global $CONSTKEYIEVER = "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer"

Global $AppTitle = "Proxy Changer"

ProxySetup()

While 1
    Sleep(100)
WEnd

Func ProxySetup()
    $proxyRegServer = RegRead($CONSTKEYPROXY, "ProxyServer")
    $proxyEnable = RegRead($CONSTKEYPROXY, "ProxyEnable")
    $proxyOverride = RegRead($CONSTKEYPROXY, "ProxyOverride")
    $proxyRegHomePage = RegRead($CONSTKEYHOME, "Start Page")
    $proxyGetVersion = RegRead($CONSTKEYIEVER, "Version")
    $proxyAutoSettings = RegRead($CONSTKEYAUTO, "DefaultConnectionSettings")
    $IEVersion = StringLeft($proxyGetVersion, 1)
    $autoConfigUrl = RegRead($CONSTKEYPROXY, "AutoConfigUrl")

    If $autoConfigUrl = -1 Then
        $autoConfigUrl = ""
    EndIf

    $proxyAutoTemp = StringMid($proxyAutoSettings, 19, 2)

    Switch $proxyAutoTemp
        Case "03"
            $autoDetect = $GUI_UNCHECKED
            $autoConfig = $GUI_UNCHECKED
        Case "0B"
            $autoDetect = $GUI_CHECKED
            $autoConfig = $GUI_UNCHECKED
        Case "0F"
            $autoDetect = $GUI_CHECKED
            $autoConfig = $GUI_CHECKED
        Case "07"
            $autoDetect = $GUI_UNCHECKED
            $autoConfig = $GUI_CHECKED
        Case "01"
            $autoDetect = $GUI_UNCHECKED
            $autoConfig = $GUI_UNCHECKED
        Case "09"
            $autoDetect = $GUI_CHECKED
            $autoConfig = $GUI_UNCHECKED
        Case "0D"
            $autoDetect = $GUI_CHECKED
            $autoConfig = $GUI_CHECKED
        Case "05"
            $autoDetect = $GUI_UNCHECKED
            $autoConfig = $GUI_CHECKED
        Case Else
            $autoDetect = $GUI_UNCHECKED
            $autoConfig = $GUI_UNCHECKED
    EndSwitch


    #Region ### START Koda GUI section ### Form=c:\my documents\autoit scripts\koda_2008-10-03\forms\form1.kxf
    $guiProxy = GUICreate("Proxy Changer", 461, 444, 294, 297)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Events")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "_Events")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_Events")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $grpProxy = GUICtrlCreateGroup("Proxy Server", 8, 154, 441, 185)
    $chkBxProxyLan = GUICtrlCreateCheckbox("Use a proxy server for you LAN", 48, 176, 193, 17)
    GUICtrlSetOnEvent(-1, "_ProxyLan_Check")
    $lblProxyAddress = GUICtrlCreateLabel("Address:", 48, 204, 45, 17)
    $inpProxyServer = GUICtrlCreateInput("", 108, 200, 137, 21)
    $lblPort = GUICtrlCreateLabel("Port:", 282, 204, 26, 17)
    $inpPort = GUICtrlCreateInput("", 320, 200, 73, 21)
    $chkBxBypass = GUICtrlCreateCheckbox("Bypass proxy server for local addresses", 48, 238, 241, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $inpBypassAdd = GUICtrlCreateEdit("", 64, 286, 297, 42)
    $grpLocation = GUICtrlCreateGroup("Network Profile", 128, 32, 237, 45)
    $radHome = GUICtrlCreateRadio("Other Network", 266, 48, 97, 17)
    $radGehl = GUICtrlCreateRadio("Main Network", 160, 48, 105, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $btnDefaults = GUICtrlCreateButton("Load Network Profile", 158, 88, 150, 33)
    GUICtrlSetOnEvent(-1, "_DefaultButton")
    $Button2 = GUICtrlCreateButton("Apply Above Settings", 158, 360, 150, 33)
    $Pic1 = GUICtrlCreatePic("C:\proxy_changer\images\Earth-Scan-128x128.bmp", 16, 16, 89, 89, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "_AsShown")

    If $proxyEnable = 1 Then
        $proxyPorttemp = StringSplit($proxyRegServer, ":")
        GUICtrlSetState($chkBxProxyLan, $GUI_CHECKED)
        GUICtrlSetData($inpProxyServer, $proxyPorttemp[1])
        GUICtrlSetData($inpPort, $proxyPorttemp[2])
        GUICtrlSetState($chkBxBypass, $GUI_CHECKED)
        GUICtrlSetData($inpBypassAdd, $proxyOverride)
        GUICtrlSetState($radGehl, $GUI_CHECKED)
    Else
        GUICtrlSetState($radHome, $GUI_CHECKED)
    EndIf
    _AutoConfig_Check() ; this will update initial state based on current values
    _ProxyLan_Check() ; this will update initial state based on current values
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

EndFunc   ;==>ProxySetup

Func _Events()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
        Case $GUI_EVENT_RESTORE
        Case Else
    EndSwitch
EndFunc   ;==>_Events

Func _DefaultButton()
    If $proxyAutoTemp = "03" Or $proxyAutoTemp = "0B" Or $proxyAutoTemp = "0F" Or $proxyAutoTemp = "07" Then
        $proxyAutoTemp = "03"
    ElseIf $proxyAutoTemp = "01" Or $proxyAutoTemp = "09" Or $proxyAutoTemp = "0D" Or $proxyAutoTemp = "05" Then
        $proxyAutoTemp = "01"
    EndIf
    Select
        Case BitAND(GUICtrlRead($radHome), $GUI_CHECKED)
            RegWrite($CONSTKEYPROXY, "ProxyEnable", "REG_DWORD", "00000000")
            DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
        Case BitAND(GUICtrlRead($radGehl), $GUI_CHECKED)
            $proxyAutoLeft = StringLeft($proxyAutoSettings, 18)
            $proxyAutoRight = StringMid($proxyAutoSettings, 21)

            $proxyAutoWrite = $proxyAutoLeft & $proxyAutoTemp & $proxyAutoRight
            RegWrite($CONSTKEYAUTO, "DefaultConnectionSettings", "REG_BINARY", $proxyAutoWrite)
            RegWrite($CONSTKEYPROXY, "ProxyEnable", "REG_DWORD", "00000001")
            RegWrite($CONSTKEYPROXY, "ProxyServer", "REG_SZ", "proxy.server.com:8080")
            RegWrite($CONSTKEYPROXY, "ProxyOverride", "REG_SZ", ";<local>")

            DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
    EndSelect
    GUIDelete($guiProxy)
    ProxySetup()
EndFunc   ;==>_DefaultButton

Func _AsShown()

    Select
        Case GUICtrlRead($chkBxAutoDetect) = $GUI_UNCHECKED And GUICtrlRead($chkBxAutoConfig) = $GUI_UNCHECKED
            $autoConfigUrlWrite = ""
            If $proxyAutoTemp = "03" Or $proxyAutoTemp = "0B" Or $proxyAutoTemp = "0F" Or $proxyAutoTemp = "07" Then
                $proxyAutoTemp = "03"
            ElseIf $proxyAutoTemp = "01" Or $proxyAutoTemp = "09" Or $proxyAutoTemp = "0D" Or $proxyAutoTemp = "05" Then
                $proxyAutoTemp = "01"
            EndIf


        Case GUICtrlRead($chkBxAutoDetect) = $GUI_CHECKED And GUICtrlRead($chkBxAutoConfig) = $GUI_UNCHECKED
            $autoConfigUrlWrite = ""
            If $proxyAutoTemp = "03" Or $proxyAutoTemp = "0B" Or $proxyAutoTemp = "0F" Or $proxyAutoTemp = "07" Then
                $proxyAutoTemp = "0B"
            ElseIf $proxyAutoTemp = "01" Or $proxyAutoTemp = "09" Or $proxyAutoTemp = "0D" Or $proxyAutoTemp = "05" Then
                $proxyAutoTemp = "09"
            EndIf

        Case GUICtrlRead($chkBxAutoDetect) = $GUI_CHECKED And GUICtrlRead($chkBxAutoConfig) = $GUI_CHECKED
            $autoConfigUrlWrite = GUICtrlRead($inpAutoConfig)
            If $proxyAutoTemp = "03" Or $proxyAutoTemp = "0B" Or $proxyAutoTemp = "0F" Or $proxyAutoTemp = "07" Then
                $proxyAutoTemp = "0F"
            ElseIf $proxyAutoTemp = "01" Or $proxyAutoTemp = "09" Or $proxyAutoTemp = "0D" Or $proxyAutoTemp = "05" Then
                $proxyAutoTemp = "0D"
            EndIf

        Case GUICtrlRead($chkBxAutoDetect) = $GUI_UNCHECKED And GUICtrlRead($chkBxAutoConfig) = $GUI_CHECKED
            $autoConfigUrlWrite = GUICtrlRead($inpAutoConfig)
            If $proxyAutoTemp = "03" Or $proxyAutoTemp = "0B" Or $proxyAutoTemp = "0F" Or $proxyAutoTemp = "07" Then
                $proxyAutoTemp = "07"
            ElseIf $proxyAutoTemp = "01" Or $proxyAutoTemp = "09" Or $proxyAutoTemp = "0D" Or $proxyAutoTemp = "05" Then
                $proxyAutoTemp = "05"
            EndIf

        Case Else

    EndSelect

    If GUICtrlRead($chkBxProxyLan) = $GUI_CHECKED Then
        $proxyEnableWrite = "00000001"
        $proxyServer = GUICtrlRead($inpProxyServer) & ":" & GUICtrlRead($inpPort)
        $proxyOverride = GUICtrlRead($inpBypassAdd) & ";<local>"
        $proxyAutoLeft = StringLeft($proxyAutoSettings, 18)
        $proxyAutoRight = StringMid($proxyAutoSettings, 21)

        $proxyAutoWrite = $proxyAutoLeft & $proxyAutoTemp & $proxyAutoRight
        RegWrite($CONSTKEYAUTO, "DefaultConnectionSettings", "REG_BINARY", $proxyAutoWrite)
        RegWrite($CONSTKEYPROXY, "ProxyEnable", "REG_DWORD", $proxyEnableWrite)
        RegWrite($CONSTKEYPROXY, "ProxyServer", "REG_SZ", $proxyServer)
        RegWrite($CONSTKEYPROXY, "ProxyOverride", "REG_SZ", $proxyOverride)
        RegWrite($CONSTKEYPROXY, "AutoConfigUrl", "REG_SZ", $autoConfigUrlWrite)
    ElseIf GUICtrlRead($chkBxProxyLan) = $GUI_UNCHECKED Then
        $proxyEnableWrite = "00000000"
        $proxyAutoLeft = StringLeft($proxyAutoSettings, 18)
        $proxyAutoRight = StringMid($proxyAutoSettings, 21)

        $proxyAutoWrite = $proxyAutoLeft & $proxyAutoTemp & $proxyAutoRight
        RegWrite($CONSTKEYAUTO, "DefaultConnectionSettings", "REG_BINARY", $proxyAutoWrite)
        RegWrite($CONSTKEYPROXY, "ProxyEnable", "REG_DWORD", $proxyEnableWrite)
        RegWrite($CONSTKEYPROXY, "AutoConfigUrl", "REG_SZ", $autoConfigUrlWrite)
    EndIf

    DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)

    GUIDelete($guiProxy)
    ProxySetup()
    EXIT
EndFunc   ;==>_AsShown



Func _AutoConfig_Check()
    Local $IsChecked = GUICtrlRead($chkBxAutoConfig)
    
    If $IsChecked = 1 Then
        GUICtrlSetState($inpAutoConfig, $GUI_ENABLE)
    Else ; $IsChecked = 4
        GUICtrlSetState($inpAutoConfig, $GUI_DISABLE)
    EndIf
EndFunc   ;==>_AutoConfig_Checked


Func _ProxyLan_Check()
    
    $IsChecked = GUICtrlRead($chkBxProxyLan)
    If $IsChecked = 1 Then
        GUICtrlSetState($inpBypassAdd, $GUI_ENABLE)
        GUICtrlSetState($inpProxyServer, $GUI_ENABLE)
        GUICtrlSetState($inpPort, $GUI_ENABLE)
        GUICtrlSetState($chkBxBypass, $GUI_ENABLE)
    Else
        GUICtrlSetState($inpBypassAdd, $GUI_DISABLE)
        GUICtrlSetState($inpProxyServer, $GUI_DISABLE)
        GUICtrlSetState($inpPort, $GUI_DISABLE)
        GUICtrlSetState($chkBxBypass, $GUI_DISABLE)
    EndIf

EndFunc   ;==>_ProxyLan_Clicked

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0