Sign in to follow this  
Followers 0
BrokenThumb

Changing IE9 Proxy settings via "Local Area Network (LAN) Settings"

4 posts in this topic

#1 ·  Posted (edited)

Hey Guys,

I've been lurking the forums for a few days now since I just got into AutoIT and honestly scripting in general. I know a bit of Pascal, but not much more...

Anywho I've started a project to help me at my job by automating some of the soul crushing tasks like "The internet on my laptop isn't working" or "***" software isn't running right." You know the kind of tier 1 questions you have to take care of that really make you cringe.

Basically right now I'm working on creating a script that will automatically alternate your proxy settings in IE9 from our branch's proxy server to auto detect. The issue I've run into is that my script will work....but randomly. It will usually run the first time after saving the script but if I try to run it again it gets to the LAN window and just dies out with no error message. I've done a bit of searching on the forum, but didn't find anything that quite met my needs.

I'm sure it's something easy, but I've spent close to an hour messing around with this ControlClick command.

Run ( "cmd" )
WinWaitActive ( "Administrator: C:\Windows\System32\cmd.exe" )
Send ( "rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,4 {ENTER}" )
WinWaitActive ( "Internet Properties" )
WinClose ( "Administrator: C:\Windows\System32\cmd.exe" )
Send ( "!l" )
WinActivate ( "Local Area Network (LAN) Settings" )
ControlClick ( "Local Area Network (LAN) Settings", "Use a pro&xy server for your LAN (These settings will not apply to dial-up or VPN connections).", 1570 )
;ControlClick ( "Local Area Network (LAN) Settings", "&Automatically detect settings", 1573 )

I've commented out the second ControlClick to try and figure out why I can't get this first command to consistently work. Any help would be greatly appreciated and if I manage to get her running I'll be sure to post my findings.

Thanks Guys!

Edited by SilasMontgommeri

Share this post


Link to post
Share on other sites



Well that's embarrassing and obnoxious :doh: stupid 20/20 hindsight...

Thanks a ton! The second I put that in it started running just fine.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Using the ideas above, this code will manipulate the two checkbox-buttons in the "Automatic configuration" section of that Local Area Network (LAN) Settings dialog.

1) It launches Internet Properties with the Connections tab active.

2) Clicks the LAN Settings button.

3) Checks or UnChecks each button.

4) Clicks the OK buttons when done to save the settings.

We need the lower button checked to access the intra or internet and then both unchecked to access a certain grouping of SOME of our vendor's Java based applications in our network...but not all groupings or all applications - a real pain.

So, I am stuggling with running this code to correctly set the boxes before launching a web link or launching the vendor's applications, or just have the user directly run the code (in non-test form, of course)...

I have not tried or know yet if the IE Control Panels can be hidden instead of visible while this script is running but it might be best to do that.

#region Test Code
_LanAutoConfigOffOff()
Sleep(2000)
_LanAutoConfigOffOn()
Sleep(2000)
_LanAutoConfigOnOff()
Sleep(2000)
_LanAutoConfigOnOn()
Sleep(2000)
#endregion Test Code
Func _LanAutoConfigOffOff()
Return _ConfigLAN("UnCheck", "UnCheck")
EndFunc ;==>_LanAutoConfigOffOff
Func _LanAutoConfigOffOn()
Return _ConfigLAN("UnCheck", "Check")
EndFunc ;==>_LanAutoConfigOffOn
Func _LanAutoConfigOnOff()
Return _ConfigLAN("Check", "UnCheck")
EndFunc ;==>_LanAutoConfigOnOff
Func _LanAutoConfigOnOn()
Return _ConfigLAN("Check", "Check")
EndFunc ;==>_LanAutoConfigOnOn
Func _ConfigLAN($autoDetSettings, $useAutoConfigScript)
; Launch the Internet Explorer Control Panel, Internet Properties dialog displaying the Connections tab (tab # 4).
Run(@ComSpec & " /c " & 'rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,4', "", "")
WinActivate("Internet Properties")
If WinWaitActive("Internet Properties") Then
; Click "LAN settings" Button.
If ControlClick("Internet Properties", "", "[CLASS:Button; TEXT:&LAN settings]", "main") Then
; Take action on the two Automatic configuration checkbox buttons.)
WinActivate("Local Area Network (LAN) Settings")
If WinWaitActive("Local Area Network (LAN) Settings") Then
    ControlCommand("Local Area Network (LAN) Settings", "", "[CLASS:Button; TEXT:&Automatically detect settings]", $autoDetSettings)
    If @error <> 1 Then
     WinActivate("Local Area Network (LAN) Settings")
     If WinWaitActive("Local Area Network (LAN) Settings") Then
     ControlCommand("Local Area Network (LAN) Settings", "", "[CLASS:Button; TEXT:Use automatic configuration &script]", $useAutoConfigScript)
     If @error <> 1 Then
     ; Success Setting both checkbox buttons.
     ; Click "OK" Button in LAN dialog.
     WinActivate("Local Area Network (LAN) Settings")
     If WinWaitActive("Local Area Network (LAN) Settings") Then
        If ControlClick("Local Area Network (LAN) Settings", "", "[CLASS:Button; TEXT:OK]", "main") Then
         ; Click "OK" Button in main Dialog.
         WinActivate("Internet Properties")
         If WinWaitActive("Internet Properties") Then
         If ControlClick("Internet Properties", "", "[CLASS:Button; TEXT:OK]", "main") Then
         ; Success.
         Return True
         EndIf
         EndIf
        EndIf
     EndIf
     EndIf
     EndIf
    EndIf
EndIf
EndIf
EndIf
MsgBox(0, "IE LAN Settings - Error", "Script """ & @ScriptName & """ failed to: " & @CRLF & _
$autoDetSettings & " (Top one) - Automatically detect settings." & @CRLF & _
$useAutoConfigScript & " (Bottom one) - Use automatic configuration script.")
Return False
EndFunc ;==>_ConfigLAN
#cs
; The Internet Properties Connections Tab:
>>>> Window <<<<
Title: Internet Properties
Class: #32770
Position: 176, 176
Size: 413, 528
Style: 0x94C820CC
ExStyle: 0x00050501
Handle: 0x001D037E

>>>> Control <<<<
Class: Button
Instance: 10
ClassnameNN: Button10
Name:
Advanced (Class): [CLASS:Button; INSTANCE:10]
ID: 1580
Text: &LAN settings

; The LAN Settings Dialog:
>>>> Window <<<<
Title: Local Area Network (LAN) Settings
Class: #32770
Position: 179, 198
Size: 384, 332
Style: 0x94C800CC
ExStyle: 0x00010101
Handle: 0x00E50EC8

; Top Button (Checkbox)
>>>> Control <<<<
Class: Button
Instance: 2
ClassnameNN: Button2
Name:
Advanced (Class): [CLASS:Button; INSTANCE:2]
ID: 1573
Text: &Automatically detect settings

; Bottom Button (Checkbox)
>>>> Control <<<<
Class: Button
Instance: 3
ClassnameNN: Button3
Name:
Advanced (Class): [CLASS:Button; INSTANCE:3]
ID: 1569
Text: Use automatic configuration &script
#ce
Edited by CraigA

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