Jump to content
Sign in to follow this  
bwq

DLLCall fails to do anything

Recommended Posts

bwq

After I create my Internet.Application object using _IECreate, I use the following DLL call to change the user agent:

Description in API:

HRESULT UrlMkSetSessionOption(

DWORD dwOption,

__in_bcount_opt(dwBufferLength) LPVOID pBuffer,

DWORD dwBufferLength,

__reserved DWORD dwReserved

);

dwOption

[in] An unsigned long integer value that contains the option to set. This can be one of the following values.

INTERNET_OPTION_PROXY

Sets the proxy settings. pBuffer must contain an INTERNET_PROXY_INFO structure. INTERNET_OPTION_PROXY and INTERNET_PROXY_INFO are defined in the Wininet.h file. For more information, see Introduction to the Microsoft Win32 Internet Functions.

INTERNET_OPTION_REFRESH

Sets the value that determines if the proxy information can be reread from the registry. The value TRUE indicates that the proxy information can be reread from the registry. For more information, see Introduction to the Microsoft Win32 Internet Functions.

URLMON_OPTION_USERAGENT

Sets the user agent string for this process.

URLMON_OPTION_USERAGENT_REFRESH

Refreshes the user agent string from the registry for this process.

pBuffer

[in] A pointer to the buffer containing the new session settings.

dwBufferLength

[in] An unsigned long integer value that contains the size of pBuffer.

dwReserved

[in] Reserved. Must be set to 0.

I'm currently using the following DLL call:

$chk_UrlMkSetSessionOption = DllCall("urlmon.dll", "long", "UrlMkSetSessionOption", "dword", 0x10000001, "ptr", $UA, "dword", 1, "dword", 0)

After that, I navigate to my test page with:

$OIE.navigate("http://localhost/log-user-agent.php")

When I check my logs, however, I still see the normal (MSIE) user-agent. I have no clue what I'm doing wrong here, so help would be much appreciated!

Share this post


Link to post
Share on other sites
rover

you don't show the struct but one thing is dwBufferLength is not set with DllStructGetSize()

Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites
bwq

Not sure what you mean by the structure, I didn't create anything.

$chk_UrlMkSetSessionOption = DllCall("urlmon.dll", "long", "UrlMkSetSessionOption", "dword", 0x10000001, "ptr", $UA, "dword", 1, "dword", 0)

is all I use. $UA = "X", it's the user-agent.

I tried your code Authenticity, but still no change in the user-agent. I wonder what's wrong.

*Edit: here's the entire function:

Func CHANGEUA($UAGENT = "X")

$UA = "X"

Dim $tBuff = DllStructCreate('char[10]')
    DllStructSetData($tBuff, 1, 'UserAgent')

$chk_UrlMkSetSessionOption = DllCall("urlmon.dll", "long", "UrlMkSetSessionOption", "dword", 0x10000001, "ptr", DllStructGetPtr($tBuff), "dword", 10, "dword", 0)

$OIE.navigate("http://localhost/testsubmit2")


EndFunc

Testsubmit2 gets the user-agent and referrer and writes it to a log file.

API: http://msdn.microsoft.com/en-us/library/aa918202.aspx

It would be nice to be able to use the return, but as soon as I set the return type to str with "DllCall("urlmon.dll, "str",...) it just crashes the application.

Edited by bwq

Share this post


Link to post
Share on other sites
rover

you can't use a string for pBuffer, it must be a pointer to a struct as Authenticity showed you.

search google and google groups with URLMON_OPTION_USERAGENT

there are issues with IE8 and usage apparently

on the whole MSDN, Google, Usenet and programming sites are more useful for getting info like this

http://groups.google.ca/groups?hl=en&q...sa=N&tab=wg

seems to be another method here, look for section 'Retrieving Individual Options'

its related to the link Authenticity just posted

Setting and Retrieving Internet Options

http://msdn.microsoft.com/en-us/library/aa385384(VS.85).aspx


I see fascists...

Share this post


Link to post
Share on other sites
Electon

is there no solution for this? i really need to change the user agent for an embedded IE control

Share this post


Link to post
Share on other sites
Electon

anyone have an example of how to set proxy with this method?

Edited by Electon

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.