Sign in to follow this  
Followers 0
BrokenThumb

Proxy Script Hangs when adding "@SW_HIDE" to Run Function.

5 posts in this topic

Hey All,

Its me again, trying to hammer through some more scripts today.

I was able to get this script up and running to change proxy settings automatically on IE9 and I wrote it in a way that my Users will be able to get visual feedback that their settings are changing.

; Script Start

;This portion launches the Internet Properties menu.

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" )

;This section launches the LAN Settings.
Send ( "!l" ) ;"Alt + l"

;The following unchecks the proxy server radio and sets it to Auto detect.
WinWaitActive ( "Local Area Network (LAN) Settings" )
ControlCommand ( "Local Area Network (LAN) Settings", "", "Button6", "UnCheck", "" )
ControlCommand ( "Local Area Network (LAN) Settings", "", "Button2", "Check", "" )

;This segment backs you out and closes the menu then displays a mesage letting you know the task is complete. Closes auto after 5 seconds.
Sleep ( 1000 ) ;One Second break in script to show user the proxy settings have been changed.
ControlClick ( "Local Area Network (LAN) Settings", "OK", 1 )
WinWaitActive ( "Internet Properties" )
ControlClick ( "Internet Properties", "OK", 1 )
MsgBox ( 0, "Proxy settings have been set to offsite.", "Your proxy settings have been changed. This window will close in five seconds.", 5 )

However as it is set up now, it shows the command prompt and I would like to remove that. So I looked up the RUN Function help page and I find that I need to add @SW_HIDE to make windows run in the background. However every time I make adjustments. (Code below) it hangs and keeps pausing itself. Looked around the forum and couldn't quite see my issue so I was hoping someone might be able to point out my fail for me.

; Script Start

;This portion launches the Internet Properties menu.

Run ( "cmd", "", @SW_HIDE )
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" )

;This section launches the LAN Settings.
Send ( "!l" ) ;"Alt + l"

;The following unchecks the proxy server radio and sets it to Auto detect.
WinWaitActive ( "Local Area Network (LAN) Settings" )
ControlCommand ( "Local Area Network (LAN) Settings", "", "Button6", "UnCheck", "" )
ControlCommand ( "Local Area Network (LAN) Settings", "", "Button2", "Check", "" )

;This segment backs you out and closes the menu then displays a mesage letting you know the task is complete. Closes auto after 5 seconds.
Sleep ( 1000 ) ;One Second break in script to show user the proxy settings have been changed.
ControlClick ( "Local Area Network (LAN) Settings", "OK", 1 )
WinWaitActive ( "Internet Properties" )
ControlClick ( "Internet Properties", "OK", 1 )
MsgBox ( 0, "Proxy settings have been set to offsite.", "Your proxy settings have been changed. This window will close in five seconds.", 5 )

Thanks Guys!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, SilasMontgommeri. If you're hiding the window, how do you expect the WinWaitActive or Send commands to ever take effect? If you want to send to a hidden window you'll have to use ControlSend, although the help file does mention that it can be unreliable for command prompts. Or check opening the applet with ShellExecute instead and cut out the middle man :)

ShellExecute("rundll32.exe", 'shell32.dll,Control_RunDLL inetcpl.cpl,,4')
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Ahhhh...I thought that when the window was hidden it would still take commands, just be hidden from the user's view. That makes since when you put it that way.

I tried out your ShellExecute Function and it worked like a dream. I'll be sure to use that one instead.

It's just a lot to try and take in all at once :)

Thanks for the help JLogan!

Share this post


Link to post
Share on other sites

Glad that worked for you. It is definitely a lot, but we all had a "Day 1" :) If you run into any bumps along the way, don't be afraid to ask questions.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

... and I wrote it in a way that my Users will be able to get visual feedback that their settings are changing.

They could also interfere with the script by activating other windows before it is finished...

I would use registry settings to change proxy settings. Halla if you need example...

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