Jump to content

Setting Proxy with RegWrite & Embedded IE Objects


Recommended Posts

Hello. I am having a problem. My program has an embedded IE object in it. The only way to set a proxy for use in it is to add the proxy information to [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings] . I have done that successfully. The problem is that for the setting to take effect, I have to restart my autoit program before the embedded browser is using the proxy. Is there any way I can get the browser object to rehash the registry keys or any way that I can refresh or recreate the browser object itself in order to allow it to use the new proxy settings so that my entire autoit program doesnt have to be restarted? thank you.

Link to comment
Share on other sites

I'm not sure how your script works or anything (no code presented) but I would think that IE wouldn't look for a proxy until the IE object is called? If that is the case, then maybe a check somewhere before the called IE object to check the registry for the key, if it's there then continue, if not, then add it.

By my thinking, when the object is then called after the value is added, it will read and load the value when it loads the object...

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I'm not sure how your script works or anything (no code presented) but I would think that IE wouldn't look for a proxy until the IE object is called? If that is the case, then maybe a check somewhere before the called IE object to check the registry for the key, if it's there then continue, if not, then add it.

By my thinking, when the object is then called after the value is added, it will read and load the value when it loads the object...

yeah thats fine but the problem is that I need my program to keep changing the proxy. so if a proxy is set, then my program loads the IE object, then changes the proxy to something else, how do I get it to use the new proxy without restarting my whole program?

Link to comment
Share on other sites

Hi,

so if a proxy is set, then my program loads the IE object, then changes the proxy to something else

Why you don't change order? If a proxy is set, check if this is the proxy you want to have.

If the proxy is another one, change proxy settings in registry to the values you want and then load IE object.

At exit of your program rewrite old proxy settings if you want or if you have to.

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi,

Why you don't change order? If a proxy is set, check if this is the proxy you want to have.

If the proxy is another one, change proxy settings in registry to the values you want and then load IE object.

At exit of your program rewrite old proxy settings if you want or if you have to.

;-))

Stefan

no. you dont understand. i need my program to set a proxy, load a web site, then set a different proxy, load the web site again... all automated by itself.

Link to comment
Share on other sites

Hi,

just a guess, i can't test because no proxies are available for me:

#include <WindowsConstants.au3>
#include <IE.au3>

_IEErrorHandlerRegister ()

Global $oIE, $GUIActiveX
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
_createembedded ()
$GUI_Button_Destroy = GUICtrlCreateButton("destroy", 10, 420, 100, 30)
GUISetState()       ;Show GUI

_IENavigate ($oIE, "http://www.autoitscript.com")

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Destroy
            $oIE = 0
            GUICtrlDelete ($GUIActiveX)
            _createembedded ()
            _IENavigate ($oIE, "http://www.autoitscript.com")
    EndSelect
WEnd

GUIDelete()

Exit

Func _createembedded ()
    $oIE = _IECreateEmbedded ()
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
EndFunc

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

  • 4 weeks later...

990j0, thank you but your code did not work. You dont need to have a proxy to test this theory. even if the proxy is dead or not even a proxy at all you would see the browser object page display an error if the proxy setting had been applied to the browser object. Here is your code revised but still isnt working properly:

#include <WindowsConstants.au3>
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

_IEErrorHandlerRegister ()

Global $oIE, $GUIActiveX
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
_createembedded ()
$GUI_Button_Destroy = GUICtrlCreateButton("destroy", 10, 420, 100, 30)
GUISetState()       ;Show GUI

_IENavigate ($oIE, "http://www.ipchicken.com")

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Destroy
            $oIE = 0
            GUICtrlDelete ($GUIActiveX)
            $GUIActiveX = 0
;set proxy
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "1")
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ","host-190-95-174-16.manta.telconet.net:3128")
            _createembedded ()
;go back to ipchicken (should see new IP or error)
            _IENavigate ($oIE, "www.ipchicken.com")
;turn proxy setting back off
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "0")
    EndSelect
WEnd

GUIDelete()

Exit

Func _createembedded ()
    $oIE = _IECreateEmbedded ()
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
EndFunc

someone please help! what is supposed to happen in this code is that the proxy setting gets applied to the browser so when we visit ipchicken the second time, it should tell us our new IP address (or give browser error if you didn't use a real proxy), but instead the setting does not get applied unless you restart the entire program. Please someone tell me there is a way.

Edited by CheshireSoft
Link to comment
Share on other sites

When you change the proxy you need to restart the (Close all IE windows) browser so the changes can take effect.

I don't have any browser windows open besides the embedded brower object in the program. It would be nice to see one of the developers comment on this thread. I have even created a feature request for this.

Link to comment
Share on other sites

Hi,

as in helpfile for _IECreateEmbedded:

_IEQuit cannot be used with this object. The object will be destroyed when its parent GUI is destroyed.

this might work:

#include <WindowsConstants.au3>
#include <IE.au3>

_IEErrorHandlerRegister ()

Global $oIE, $GUIActiveX, $Gui, $GUI_Button_Destroy
_createembedded ()
_IENavigate ($oIE, "http://www.autoitscript.com")

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Destroy
            $oIE = 0
            GUIDelete ($Gui)
            _createembedded ()
            _IENavigate ($oIE, "http://www.autoitscript.com")
    EndSelect
WEnd

GUIDelete()

Exit

Func _createembedded ()
    $Gui = GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
    $oIE = _IECreateEmbedded ()
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $GUI_Button_Destroy = GUICtrlCreateButton("destroy", 10, 420, 100, 30)
    GUISetState()       ;Show GUI
EndFunc

;-))

Stefan

P.S: You might use tool regmon, to see, if at object creation the IE values are read out of registry hive.

Link to comment
Share on other sites

Hi,

as in helpfile for _IECreateEmbedded:

this might work:

#include <WindowsConstants.au3>
#include <IE.au3>

_IEErrorHandlerRegister ()

Global $oIE, $GUIActiveX, $Gui, $GUI_Button_Destroy
_createembedded ()
_IENavigate ($oIE, "http://www.autoitscript.com")

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Destroy
            $oIE = 0
            GUIDelete ($Gui)
            _createembedded ()
            _IENavigate ($oIE, "http://www.autoitscript.com")
    EndSelect
WEnd

GUIDelete()

Exit

Func _createembedded ()
    $Gui = GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
    $oIE = _IECreateEmbedded ()
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $GUI_Button_Destroy = GUICtrlCreateButton("destroy", 10, 420, 100, 30)
    GUISetState()       ;Show GUI
EndFunc

;-))

Stefan

P.S: You might use tool regmon, to see, if at object creation the IE values are read out of registry hive.

NICE! This is the first time in this forum I have seen a solution to rehash IE settings in an embedded browser object. There have been other threads like mine that went nowhere. Your code worked nicely. I have one last question. With this code, the GUI gets deleted and then recreated. Is there any way you can think of that we might make it look like that hasn't happened to the user? When running this code the GUI window momentarily disappears and then reappears. If we can somehow make it seem as though it didn't disappear then this solution will be perfected.

I have updated the code to be more tester friendly.. here it is:

#include <WindowsConstants.au3>
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

_IEErrorHandlerRegister ()

Global $oIE, $GUIActiveX, $Gui, $BTN_ProxyOn, $BTN_ProxyOff
_createembedded ()
_IENavigate ($oIE, "http://ipchicken.com")

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $BTN_ProxyOn
            $oIE = 0
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "1")
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ","89.189.189.204.sta.211.ru:3128")
            rehash()
            _IENavigate ($oIE, "http://ipchicken.com")
        Case $msg = $BTN_ProxyOff
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "0")
            rehash()
            _IENavigate ($oIE, "http://ipchicken.com")
    EndSelect
WEnd

GUIDelete()

Exit

Func rehash()
    GUIDelete($Gui)
    _createembedded()
EndFunc

Func _createembedded ()
    $Gui = GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
    $oIE = _IECreateEmbedded ()
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $BTN_ProxyOn = GUICtrlCreateButton("Proxy On", 10, 420, 100, 30)
    $BTN_ProxyOff = GUICtrlCreateButton("Proxy Off", 120, 420, 100, 30)
    GUISetState()       ;Show GUI
EndFunc
Edited by CheshireSoft
Link to comment
Share on other sites

Hi,

since ipchicken.com is dynamic (always other adverts are displayed), the site never looks the same.

So you always would recognize a change.

As your buttons doing some changes and the changes need a restart of the gui, why don't show action to user:

#include <WindowsConstants.au3>
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

_IEErrorHandlerRegister ()

Global $oIE, $GUIActiveX, $Gui, $BTN_ProxyOn, $BTN_ProxyOff
_createembedded ()
;_IENavigate ($oIE, "http://ipchicken.com") ;put in _creatembedded

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $BTN_ProxyOn
            $oIE = 0
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "1")
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ","89.189.189.204.sta.211.ru:3128")
            rehash()
        Case $msg = $BTN_ProxyOff
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "0")
            rehash()
    EndSelect
WEnd

GUIDelete()

Exit

Func rehash()
    GUIDelete($Gui)
    _Splash ()
    _createembedded()
EndFunc

Func _Splash ()
    SplashTextOn ("Gui Restart!", "For changing the proxy, the gui has to restart!" & @CRLF & "Please wait....", 350, 80, -1, -1, 4)
EndFunc

Func _createembedded ()
    $Gui = GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) ; remove $WS_VISIBLE -> GUISetState shows windows
    $oIE = _IECreateEmbedded ()
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $BTN_ProxyOn = GUICtrlCreateButton("Proxy On", 10, 420, 100, 30)
    $BTN_ProxyOff = GUICtrlCreateButton("Proxy Off", 120, 420, 100, 30)
    _IENavigate ($oIE, "http://ipchicken.com")
    SplashOff ()
    GUISetState()       ;Show GUI
EndFunc
Link to comment
Share on other sites

Hi,

since ipchicken.com is dynamic (always other adverts are displayed), the site never looks the same.

So you always would recognize a change.

As your buttons doing some changes and the changes need a restart of the gui, why don't show action to user:

#include <WindowsConstants.au3>
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

_IEErrorHandlerRegister ()

Global $oIE, $GUIActiveX, $Gui, $BTN_ProxyOn, $BTN_ProxyOff
_createembedded ()
;_IENavigate ($oIE, "http://ipchicken.com") ;put in _creatembedded

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $BTN_ProxyOn
            $oIE = 0
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "1")
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ","89.189.189.204.sta.211.ru:3128")
            rehash()
        Case $msg = $BTN_ProxyOff
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", "0")
            rehash()
    EndSelect
WEnd

GUIDelete()

Exit

Func rehash()
    GUIDelete($Gui)
    _Splash ()
    _createembedded()
EndFunc

Func _Splash ()
    SplashTextOn ("Gui Restart!", "For changing the proxy, the gui has to restart!" & @CRLF & "Please wait....", 350, 80, -1, -1, 4)
EndFunc

Func _createembedded ()
    $Gui = GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) ; remove $WS_VISIBLE -> GUISetState shows windows
    $oIE = _IECreateEmbedded ()
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
    $BTN_ProxyOn = GUICtrlCreateButton("Proxy On", 10, 420, 100, 30)
    $BTN_ProxyOff = GUICtrlCreateButton("Proxy Off", 120, 420, 100, 30)
    _IENavigate ($oIE, "http://ipchicken.com")
    SplashOff ()
    GUISetState()       ;Show GUI
EndFunc

thank you. i didn't know about these splash functions. do animated gifs work in SplashImageOn ?
Link to comment
Share on other sites

Hi,

no, they don't. Only 'static' gif,bmp and so on.

For creating a gui with animated gif, have a look at this thread

http://www.autoitscript.com/forum/index.php?showtopic=83420&st=0&p=779187&hl=animated%20gif&fromsearch=1&#entry779187

and built your own, instead of using Splash....

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

  • 2 weeks later...

i wanna to ask, i use this topic and make a sock changer. but somehow, i can't make it work

#include <GUIConstants.au3>
#include <IE.au3> 
#Include <File.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#Include <Constants.au3>
#include <StaticConstants.au3>



Global $oIE, $GUIActiveX, $Gui, $button_1, $treeview 
Func _creatGUI()
$Gui = GUICreate( "my bot", 1024 , 900)
$oIE = _IECreateEmbedded ()
GUICtrlCreateObj($oIE, 350, 30, 650, 850)
$button_1 = GUICtrlCreateButton ("change ip",  90, 800, 70 )
GUICtrlCreateTabItem("                sock and setting               ")
$treeview = GUICtrlCreateTreeView(10, 30, 180, 650, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
GUICtrlCreateTreeViewItem( "direct", $treeview)
$CountLines = _FileCountLines("sock.txt")
If @error = 1 Then
    _GUICtrlTreeView_InsertItem( $treeview, "Unable to open file.")
Else
    Local $subtree[$CountLines+1]
    $handle = FileOpen( "sock.txt", 0)
    for $k = 1 to $CountLines
    $subtree[$k] = GuiCtrlCreateTreeViewItem(FileReadLine ( $handle, $k), $treeview)
    next
    FileClose( $handle)
EndIf
GUISetState ()
EndFunc
_creatGUI()
While 1
    $msg = GUIGetMsg() ; this checks for a message/input from the GUI.
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit ; this states, on an exit event, exit the loop.
    case $msg = $button_1       
            changeip()
            Sleep(5000)
            $oIE = 0
            GUIDelete ($Gui)
            _creatGUI()
    EndSelect
Wend

GUIDelete()

Exit


func changeip()
    $s=GUICtrlRead($treeview, 1)
If $s="" Then
regwrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\","ProxyEnable","REG_DWORD","0")
else
regwrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\","ProxyEnable","REG_DWORD","1")
regwrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\","ProxyServer","REG_SZ","socks="&$s)
endif
_IENavigate($oIE,"http://ip.xanta.net/")
EndFunc
Edited by fgthhhh
Link to comment
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
 Share

  • Recently Browsing   0 members

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