Sign in to follow this  
Followers 0
insane42

InternetSetOption and Registry

9 posts in this topic

Hi All -

Just started experimenting with AutoIT to create a simple app.  All I'm looking to do is set various proxies and enable/disable the proxy for the logged in user.  Everything works GREAT the FIRST time.  Each subsequent time I click a menu entry, the registry update works fine but then the InternetSetOption DLL call sets it back!!  If I exit the app then restart it and select an option, it "sticks".

Here is the simple code.  Anyone have any ideas?  Again, the registry changes work, but the DLL call only works correctly the first time. :(  I verified this by putting a 5 second sleep before running RefreshIE while constantly pressing F5 in regedit.  I'd see the value change, then 5 seconds later change back (on all subsequent attempts).

Thanks in advance!!

#include <TrayConstants.au3>

Opt("TrayMenuMode", 3)
TraySetIcon("imageres.dll", 179)
TraySetToolTip("Switch Proxy")

Local $mnu_Localhost = TrayCreateItem("Use localhost")
Local $mnu_Avnet = TrayCreateItem("Use Other")
TrayCreateItem("")
Local $mnu_Disable = TrayCreateItem("Disable Proxy")
Local $mnu_Enable = TrayCreateItem("Enable Proxy")
Local $mnu_Exit = TrayCreateItem("E&xit")

TraySetState($TRAY_ICONSTATE_SHOW)
ManageMenu()

Func ManageMenu()
   While True
      Switch TrayGetMsg()
         Case $mnu_Localhost
            SetProxy("localhost:8080")
         Case $mnu_Avnet
            SetProxy("other:8080")
         Case $mnu_Disable
            EnableDisable(0)
         Case $mnu_Enable
            EnableDisable(1)
         Case $mnu_Exit
            ExitLoop
      EndSwitch
   Wend
EndFunc

Func SetProxy($Proxy)
   RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ", $Proxy)
   RefreshIE()
EndFunc

Func EnableDisable($Value)
   RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", $Value)
   RefreshIE()
EndFunc

Func RefreshIE()
   DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 37, 'str', 0, 'long', 0)
EndFunc

CS

Share this post


Link to post
Share on other sites



Thanks for the link Cor, but this doesn't help me. :/

The HttpSetProxy function is applicable for the Autoit instance, and doesn't change the system proxy.  I'm just stumped as to why it works perfectly the 1st time, but not again until I restart the Autoit script.

Share this post


Link to post
Share on other sites

Strange, because this (fromt that thread)..

Func RefreshIE()
    DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
    DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 37, 'str', 0, 'long', 0)
EndFunc

Works perfectly on my system!

;o) Cor


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

I've got that exact code in there.  Setting one works, but setting the 2nd doesn't.  It still only works the first time I choose one (doesn't matter which).

For example, I've got Regedit up and the proxy shows localhost:8080.  I start up the script and select the "other" and refresh the registry.  It changes to "other:8080".  Great!  So now I select localhost.  Refresh the registry and it still shows "other:8080".  If I put a sleep for 5 seconds before RefreshIE(), I can see the registry change correctly, then change right back once the DLL calls are made.

Share this post


Link to post
Share on other sites

I understand what you are saying. But like I said, the above code works great here (win8.1 x64) I can flip back and forth any amount of times and the registry flips back and forth with it. If I refresh IE after each change, I get the relevant error message. It's all good. The code works.

Maybe there is something else on your system interfering.

;o) Cor

ps. check out TrayItemSetState() - that menu needs checkmarks!


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

ps. check out TrayItemSetState() - that menu needs checkmarks!

 

I agree.  Was going to add the checkmarks once I figured out why it was misbehaving.  I'm on Win7.  Thought this would have been a simple one.  :

Thanks for the help corz.

Anyone else w/ Win7 try this out and see if they can replicate the "bad" behaviour?

Share this post


Link to post
Share on other sites

I just wanted to close the loop on this.  I don't know what is causing it, but it's something w/ my system that is causing the behavior I'm seeing.  I had someone else w/ Win7 try it out as well, and it works perfectly fine for him.  Love trying to create something for myself that only works for everyone else!  :P

Thanks for the replies, corz.

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