#Region Compiler directives section
#Compiler_Prompt=n
#Compiler_AUTOIT3=
#Compiler_AUT2EXE=
#Compiler_Icon=Globe.ico
#Compiler_OutFile=
#Compiler_OutFile_Type=exe
#Compiler_Compression=4
#Compiler_Allow_Decompile=y
#Compiler_PassPhrase=
#Compiler_UseUpx=y
#Compiler_Res_Comment= Change IE Proxy
#Compiler_Res_Description=Change IE Proxy
#Compiler_Res_Fileversion=1.2
#Compiler_Res_FileVersion_AutoIncrement=n
#Compiler_Res_LegalCopyright=Giuseppe Criaco
#Compiler_Res_Field=AutoIt Version|%AutoItVer%
#Compiler_Res_Field=Email|gcriaco@quipo.it
#Compiler_Res_Field=Release Date|21/5/2007
#Compiler_Res_Field=Name|Value
#Compiler_Res_Field=Name|Value
#Compiler_Run_Tidy=n
#Compiler_Tidy_Stop_OnError=n
#Tidy_Parameters=
#Compiler_Run_AU3Check=
#Compiler_AU3Check_Parameters=
#Compiler_AU3Check_Dat=
#Compiler_AU3Check_Stop_OnWarning=
#Compiler_AU3Check_Parameters=
#Compiler_PlugIn_Funcs=
#Compiler_Run_Before=
#Compiler_Run_After=
#Compiler_Run_cvsWrapper=n
#Run_Debug_Mode=n
#EndRegion
#Region - Include and Declarations
#include <GuiConstants.au3>
#include <GuiList.au3>
Global Const $WM_COMMAND = 0x0111
Global Const $LBN_SELCHANGE = 1
Global Const $LBN_DBLCLK = 2
Dim $asCmd[50], $iCmd = 0, $IP, $sHostName, $sEncryptPwd, $sPwd, $sUser, $iSleep = 1000, $sPutty, $iSendKeyDelay = 50
#EndRegion - Include and Declarations
If $CmdLine[0] > 0 Then _Batch()
#Region ### START Koda GUI section ### Form=c:\autoit\proxy\chgproxy.kxf
$AForm1 = GUICreate("ChgProxy v. 1.2", 235, 369, 493, 134)
$btnOk = GUICtrlCreateButton("&Start", 88, 336, 65, 25, $BS_DEFPUSHBUTTON)
$lstServer = GUICtrlCreateList("", 8, 64, 217, 97)
$btnExit = GUICtrlCreateButton("&Exit", 160, 336, 65, 25, 0)
$AGroup1 = GUICtrlCreateGroup("Settings", 8, 280, 217, 49)
$optEnabled = GUICtrlCreateRadio("Enabled", 24, 304, 73, 17)
$optDisabled = GUICtrlCreateRadio("Disabled", 144, 304, 73, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$grpProxy = GUICtrlCreateGroup("Proxy Server", 8, 8, 217, 49)
$lblProxy = GUICtrlCreateLabel("lblProxy", 24, 32, 192, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$edtExceptions = GUICtrlCreateEdit("", 8, 200, 217, 73, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData(-1, "")
$Label1 = GUICtrlCreateLabel("Exceptions:", 8, 180, 59, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
If Not FileExists(@ScriptDir & "\ChgProxy.ini") Then
MsgBox(48, "File Not Found", "Required file not found (" & @ScriptDir & "\ChgProxy.ini" & ")" & @CRLF & "" & @CRLF & "ChgProxy will now exit!!!")
Exit
EndIf
$sProxy = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer")
$iEnabled = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable")
$sExceptions = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride")
If $iEnabled Then
GUICtrlSetState($optEnabled, $GUI_CHECKED)
TrayTip("Proxy Server: ", $sProxy, 5, 1)
TraySetToolTip("Proxy Server: " & $sProxy)
GUICtrlSetData($lblProxy, $sProxy)
Else
GUICtrlSetState($optDisabled, $GUI_CHECKED)
TrayTip("Proxy Server: ", "Disabled(Direct Connection)", 5, 1)
TraySetToolTip("Proxy Server: Disabled(Direct Connection)")
GUICtrlSetData($lblProxy, $sExceptions)
EndIf
GUICtrlSetData($edtExceptions, $sExceptions)
HotKeySet("{ESC}", "_Terminate")
$sSection = IniReadSection(@ScriptDir & "\ChgProxy.ini", "Servers")
If @error Then
#Region --- CodeWizard generated code Start ---
MsgBox(16, "ChgProxy", "Unable to read the section Server")
#EndRegion --- CodeWizard generated code End ---
Exit
Else
Local $iLstIndex = 0
For $iSection = 1 To $sSection[0][0]
GUICtrlSetData($lstServer, $sSection[$iSection][0] & " (" & $sSection[$iSection][1] & ")")
If $sProxy = $sSection[$iSection][1] Then
GUICtrlSetData($grpProxy, "Proxy: " & $sSection[$iSection][0])
$iLstIndex = $iSection - 1
EndIf
Next
If $iLstIndex > 0 Then
$ret = _GUICtrlListSelectIndex($lstServer, $iLstIndex)
If ($ret == $LB_ERR) Then
MsgBox(16, "Error", "Unknown error from _GUICtrlListSelectIndex")
EndIf
EndIf
EndIf
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE Or $msg = $btnExit
_Terminate()
Case $msg = $btnOk
_Start()
EndSelect
WEnd
Func _Start()
If GUICtrlRead($optEnabled) = $GUI_CHECKED Then
$sTmpKey = GUICtrlRead($lstServer)
$sKey = StringLeft($sTmpKey, StringInStr($sTmpKey, " ("))
If $sKey = "" Then
#Region --- CodeWizard generated code Start ---
MsgBox(48, "Error Message", "No Proxy selected")
#EndRegion --- CodeWizard generated code End ---
Else
$sProxy = IniRead(@ScriptDir & "\ChgProxy.ini", "Servers", $sKey, "NotFound")
If @error Or $sProxy = "NotFound" Then
MsgBox(16, "ChgProxy", "Unable to read the Key " & $sKey)
Exit
Else
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ", $sProxy)
TrayTip("Proxy Server: ", $sProxy, 5, 1)
TraySetToolTip("Proxy Server: " & $sProxy)
GUICtrlSetData($lblProxy, $sProxy)
GUICtrlSetData($grpProxy, "Proxy: " & $sKey)
EndIf
EndIf
$sExceptions = GUICtrlRead($edtExceptions)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 1)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride", "REG_SZ", $sExceptions)
Else
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 0)
TrayTip("Proxy Server: ", "Disabled (Direct Connection)", 5, 1)
TraySetToolTip("Proxy Server: Disabled(Direct Connection)")
GUICtrlSetData($lblProxy, "Disabled (Direct Connection)")
GUICtrlSetData($grpProxy, "proxy")
EndIf
EndFunc
Func _Terminate()
Exit 0
EndFunc
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
$nNotifyCode = BitShift($wParam, 16)
$nID = BitAND($wParam, 0x0000FFFF)
$hCtrl = $lParam
If $nID = $lstServer Then
Switch $nNotifyCode
Case $LBN_DBLCLK
_Start()
Return 0
EndSwitch
EndIf
EndFunc
Func _Batch()
If (StringLower ($CmdLine[1]) <> "e" And StringLower ($CmdLine[1]) <> "d") Or _
(StringLower ($CmdLine[1]) = "e" And $CmdLine[0] < 2) Then
MsgBox(16,"Error Message","Command-line parameters: " & @CRLF & "1st: e/d (enable/disable proxy)" & @CRLF & "2nd: proxyname:port" & @CRLF & "Example: ChgProxy e MyProxy:8080")
Else
If StringLower ($CmdLine[1]) = "e" Then
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ", $CmdLine[2])
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 1)
Else
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 0)
EndIf
EndIf
_Terminate()
EndFunc