Hi all,
This is my first shared script, so please bear with me. Tips and advice are always welcome.
I have seen many attempts/theories on how to switch the proxy on and off.
Many have ridiculously large scripts, registry edits and reloads or reboots, etc...
None of which worked for me.
Here is my Solution (a bit crude, but it works for me 100%):
The Theory and what it does -
1) Toggle the Status (On|Off), (via *.ahk file)
- Opening the Internet Setting directly (inetcpl.cpl),
- Click on the Connections Tab,
- Click on Lan Settings,
- Click on Proxy Server check box,
- Click Ok to close child window,
- Click Ok to close parent window.
2) Display Status. (Msgbox)
- Run the *.bat File, (If someone knows how to convert this to AHK Script please let me know)
- Get result and save to windows clipboard,
- Get current Status from clipboard.
- Convert to a single digit (0|1),
- Compare it for the "if" statements
- Check the current status,
- Display Updated Status,
- Sleep for 3 seconds and close.
Possible Issues / Troubleshooting:
My System - Win 7 (64bit), Screen Resolution (1366 x 768)
Please note that the process used, opens up the Internet Settings Control Panel and uses a automated mouse Click process to activate the settings. (This is not ideal, but it works)
I found that when clicking on the "Proxy Server" check box, the mouse would move to a different location within that window on each run and would miss the check box. I found the same issue when using the Tab key option.
I can only assume that the Window changes sizes or is populated Dynamically and therefore changes the location of each control while loading. What I did to resolve this, was to Move the mouse to 0,0 and then move it again to 145, 210. This solved the issue and now works 100%
NB: Before running the full script,... I suggest commenting out the "Click" actions to confirm that the mouse is indeed moving to the correct position (the "Proxy Server" check box) before running the "Click" action.
*************** How it's done! ***************
Process:
1) Create a Batch (*.bat) file and insert the Script below. (If someone knows how to convert this to AHK Script please let me know)
2) Save this *bat file in the same folder as your .ahk script or change "Run, ProxyState.bat" below to your desired location.
3) Create your *ahk file and insert the Script below.
*************** Scripts Start ***************
Filename: ProxyState.bat
Contents:
@echo off
*************** Scripts End ***************
PS: The last MsgBox is just there for a visual error check to ensure that proxy value is pulling through correctly.
Enjoy.