Jump to content

Need Help Using urlmon.dll Please


Electon
 Share

Recommended Posts

Hello everyone. I have figured out how to change things such as the user agent when using an embedded IE object in my autoit applications (thanks to some code I found around here). Here is my code to change user agents:

Func userAgent($agent)
    $agentLen = StringLen($agent)
    Dim $tBuff = DllStructCreate("char["&$agentLen&"]")
    DllStructSetData($tBuff, 1, $agent)
    $chk_UrlMkSetSessionOption = DllCall("urlmon.dll", "long", "UrlMkSetSessionOption", "dword", 0x10000001, "ptr", DllStructGetPtr($tBuff), "dword", $agentLen, "dword", 0)
EndFunc

Which works perfectly. Now I have a great need to set the proxy settings in this way. I am no pro at using DLLs though. The documentation for the DLL is here: http://msdn.microsoft.com/en-us/library/ms775125(VS.85).aspx and has proxy options but I can't figure out how to do it. I would be extremely greatfull if someone could show me how to set http and socks proxies using this dll. Thank you.

Edited by Electon
Link to comment
Share on other sites

Func _SetProxy($proxy, $proxybypass = "")
    Local INTERNET_OPTION_PROXY = 38;
    Local INTERNET_OPEN_TYPE_PROXY = 3;
    Local $tBuff = DllStructCreate("dword;ptr;ptr")
    DllStructSetData($tBuff, 1, INTERNET_OPEN_TYPE_PROXY)
    Local $pproxy = DllStructCreate("char[" & (StringLen($proxy) + 1) & "]")
    DllStructSetData($pproxy, 1, $proxy)
    DllStructSetData($tBuff, 2, DllStructGetPtr($pproxy))
    Local $pproxybypass = DllStructCreate("char[" & (StringLen($proxybypass) + 1) & "]")
    DllStructSetData($pproxybypass, 1, $proxybypass)
    DllStructSetData($tBuff, 3, DllStructGetPtr($pproxybypass))
    $chk_UrlMkSetSessionOption = DllCall("urlmon.dll", "long", "UrlMkSetSessionOption", "dword", INTERNET_OPTION_PROXY, "ptr", DllStructGetPtr($tBuff), "dword", DllStructGetSize($tbuff), "dword", 0)
EndFunc

I believe this should work. It is untested though. Let me know what happens.

Link to comment
Share on other sites

Func _SetProxy($proxy, $proxybypass = "")
    Local INTERNET_OPTION_PROXY = 38;
    Local INTERNET_OPEN_TYPE_PROXY = 3;
    Local $tBuff = DllStructCreate("dword;ptr;ptr")
    DllStructSetData($tBuff, 1, INTERNET_OPEN_TYPE_PROXY)
    Local $pproxy = DllStructCreate("char[" & (StringLen($proxy) + 1) & "]")
    DllStructSetData($pproxy, 1, $proxy)
    DllStructSetData($tBuff, 2, DllStructGetPtr($pproxy))
    Local $pproxybypass = DllStructCreate("char[" & (StringLen($proxybypass) + 1) & "]")
    DllStructSetData($pproxybypass, 1, $proxybypass)
    DllStructSetData($tBuff, 3, DllStructGetPtr($pproxybypass))
    $chk_UrlMkSetSessionOption = DllCall("urlmon.dll", "long", "UrlMkSetSessionOption", "dword", INTERNET_OPTION_PROXY, "ptr", DllStructGetPtr($tBuff), "dword", DllStructGetSize($tbuff), "dword", 0)
EndFunc

I believe this should work. It is untested though. Let me know what happens.

Thank you. In what format should I pass the proxy/port to it? also, will it accept SOCKS5? I will paypal you for this help you're giving me. thank you so much.
Link to comment
Share on other sites

Func _SetProxy($proxy, $proxybypass = "")     Local $INTERNET_OPTION_PROXY = 38     Local $INTERNET_OPEN_TYPE_PROXY = 3     Local $tBuff = DllStructCreate("dword;ptr;ptr")     DllStructSetData($tBuff, 1, $INTERNET_OPEN_TYPE_PROXY)     Local $pproxy = DllStructCreate("char[" & (StringLen($proxy) + 1) & "]")     DllStructSetData($pproxy, 1, $proxy)     DllStructSetData($tBuff, 2, DllStructGetPtr($pproxy))     Local $pproxybypass = DllStructCreate("char[" & (StringLen($proxybypass) + 1) & "]")     DllStructSetData($pproxybypass, 1, $proxybypass)     DllStructSetData($tBuff, 3, DllStructGetPtr($pproxybypass))     $chk_UrlMkSetSessionOption = DllCall("urlmon.dll", "long", "UrlMkSetSessionOption", "dword", $INTERNET_OPTION_PROXY, "ptr", DllStructGetPtr($tBuff), "dword", DllStructGetSize($tbuff), "dword", 0) EndFunc

there was a syntax error in there i fixed with those local variables. I tried to pass the function the SOCKS proxy in the form of ip:port and then the page wouldn't load.

Link to comment
Share on other sites

I'm not familiar with the code at all. I merely translated it from MSDN. I'll look around and see what I can find on SOCKS proxy.

Ok, pass the parameter like "socks=127.0.0.1:12345" And replace the IP and port with whatever you have.

nice. I had tried that before and it didn't work (im used to the registry setting). the SOCKS i was using must have died because its working now. Thank you. PM me your paypal addy if you intend to collect a reward.

Link to comment
Share on other sites

No reward needed. I only helped because I understand translating structs from the MSDN can be difficult for languages like AutoIt.

would you consider writing a tutorial on doing it in autoit? being able to do this greatly extends what can be done.

Link to comment
Share on other sites

  • 3 years later...

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...