Jump to content

Recommended Posts

Posted

Hello.

I've had a project going on for the last month or so and have been managing well enough so far by using the copy/paste technique. I've searched for little snippets of code that will do roughly what I require and have got to grips with it and tweaked it to my needs but now there's one thing that I am stumped with. It's the popular topic of changing IE proxy settings. I've seen quite a few threads on here about the same thing and numerous different methods offered as a solution. The easiest would be the following;

$key = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$reg = RegWrite($key, "ProxyEnable", "REG_DWORD", "1")
$reg1 = RegWrite($key, "ProxyServer", "REG_SZ", $aProxy[$rnd])

I don't mind having to close the IE window as I've called it back up in AutoIT so it's not a problem. The thing is, IE never acts on the new proxy settings. The changes are made in the registry but IE doesn't honour them. If I put an 'Exit' in, after the above code to test, and open a new instance of IE it works, but not if the script uses _IEQuit() and then creates another instance. I've tried adding Sleep() but that doesn't help.

Can someone please assist me, let me know what I need to do to get it to acknowledge the change in proxy?

Thank you in advance, and also to those numerous people who's code I have lifted from so many threads here to get to the point I'm currently at.

Posted

You have to "reload" the environment. I had the same problem couple years ago and I have asked in this forum. I remember somebody gave me the solution.

I don't know if I still have the code but a search might give back some results.

... very easy, managed to find it instantly - see here:

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

Thanks, enaiman.

I tried adding that line to my code but it doesn't seem to be making a difference - the script will apply a random proxy the first time it's run but not during the loop. Can you take a look at the snippet below and let me know if I'm missing something silly?

Dim $aRecords
FileOpen("D:\sites.log")
If Not _FileReadToArray("d:\sites.log",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
FileClose("D:\sites.log")
FileOpen("D:\proxies.txt")
Dim $aProxy
If Not _FileReadToArray("d:\proxies.txt",$aProxy) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
EndIf
FileClose("D:\proxies.txt")

for $x = 1 to $aRecords[0]
    $rnd=random(1,$aProxy[0],1)
    $key = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
    $reg = RegWrite($key, "ProxyEnable", "REG_DWORD", "1")
    $reg1 = RegWrite($key, "ProxyServer", "REG_SZ", $aProxy[$rnd])
    ;HttpSetProxy(2, $aProxy[$rnd])
    DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
    MsgBox(0,"",$aProxy[$rnd])
    $oIE=_IECreate("http://www.whatismyip.com")
    sleep(1000)
    _IEQuit($oIE)
Next
Posted

You aren't missing anything and it should work. Put some error checking in your MsgBox after you call the dll - that way you can see if there is an error or not.

You might try adding a bit of sleep after DllCall, just to give time to refresh.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

I had tried adding a sleep after it to make sure but it didn't affect it. I've just now added a sleep(1000) and MsgBox(0,"",@error) after the DllCall but it returns 0.

Is there something else I can look for?

Would you mind checking it on your own machine - see if it works for you?

An example of the D:\proxies.txt could be;

111.177.111.44:8080

113.105.85.6:8080

113.160.23.58:8888

113.160.24.114:3128

113.53.252.106:8080

115.236.37.18:808

115.252.89.9:3128

118.182.20.242:8080

Posted

Here is what option 39 is about:

INTERNET_OPTION_SETTINGS_CHANGED

39

Notifies the system that the registry settings have been changed so that it verifies the settings on the next call to InternetConnect. This is used by InternetSetOption

Unfortunately it won't work more than once for the same IE window - sorry but I have no idea how to make your code work.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

Thanks for looking into it, I wouldn't know what to look for myself.

When I use _IEQuit() and create another instance, does it appear to the system to be the same IE window then? Bit confused by it.

  • 1 year later...
Posted

Through testing I found that it seems to be limited to the script. It will change the proxy properly (even with the same window open) if you compile your registry codes to their own executable. For some reason if you run the same code in same script, it will only make a change for the first registry change. Tried it as a #include also and no dice.

Script for proxy switched on compiled into .exe-

#include <IE.au3>
$PXYSVR = "IP"
$PXYPRT = "Port"
$key = "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings"
$reg = RegWrite($key, "ProxyEnable", "REG_DWORD", "1")
$reg1 = RegWrite($key, "ProxyServer", "REG_SZ", $PXYSVR & ":" & $PXYPRT)
DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
Sleep(2000)
$oIE = _IECreate("http://www.whatismyip.com")

Script for proxy switched off compiled into .exe-

$key = "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings"
$reg = RegWrite($key, "ProxyEnable", "REG_DWORD", "0")
DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
Sleep(2000)

Parent script to run both of them-

RunWait("PathProxy On Registry.exe")
Sleep(2000)
RunWait("PathProxy Off Registry.exe")

Might be a bit sloppy and there's probably a better way to do this, but this works for me, even as a jenky workaround. Hope this helps

Posted

To change the proxy settings without restarting Internet Explorer, I found the only way to do it was to do what you've done above, but also write the binary values to:

HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet SettingsConnectionsDefaultConnectionSettings

BEFORE doing the DLL call.

Unfortunately, I've not found a way to programatically create the binary values so I had to create these by entering each proxy value you want to use and exporting each from the registry and hard coding the binary values into the script.

Using this definitely works and allows you to switch proxies without closing IE.

NiVZ

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...