Sign in to follow this  
Followers 0
Electon

Need Help Using urlmon.dll Please

13 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



anyone? i could really use some help.

Share this post


Link to post
Share on other sites
If anyone can solve this I will paypal them. This is very important to me.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

okay I passed it an HTTP proxy and that worked. now just need to figure out how to use SOCKS.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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.

Edited by Richard Robertson

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

There are plenty of tutorials. I don't even use AutoIt as a language anymore, so there's not much point in me writing a tutorial.

Share this post


Link to post
Share on other sites

It's easy. Just prepend socks= to the ip/port

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