bwq Posted April 18, 2009 Posted April 18, 2009 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!
Authenticity Posted April 18, 2009 Posted April 18, 2009 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)
rover Posted April 18, 2009 Posted April 18, 2009 (edited) you don't show the struct but one thing is dwBufferLength is not set with DllStructGetSize() Edited April 18, 2009 by rover I see fascists...
bwq Posted April 18, 2009 Author Posted April 18, 2009 (edited) 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") EndFuncTestsubmit2 gets the user-agent and referrer and writes it to a log file.API: http://msdn.microsoft.com/en-us/library/aa918202.aspxIt 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 April 18, 2009 by bwq
Authenticity Posted April 18, 2009 Posted April 18, 2009 Maybe you're looking for this -> http://msdn.microsoft.com/en-us/library/aa385328(VS.85).aspx
rover Posted April 18, 2009 Posted April 18, 2009 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_USERAGENTthere are issues with IE8 and usage apparentlyon the whole MSDN, Google, Usenet and programming sites are more useful for getting info like thishttp://groups.google.ca/groups?hl=en&q...sa=N&tab=wgseems to be another method here, look for section 'Retrieving Individual Options'its related to the link Authenticity just postedSetting and Retrieving Internet Optionshttp://msdn.microsoft.com/en-us/library/aa385384(VS.85).aspx I see fascists...
bwq Posted April 18, 2009 Author Posted April 18, 2009 Maybe you're looking for this -> http://msdn.microsoft.com/en-us/library/aa385328(VS.85).aspxThanks, but I don't think that'll work with IE.au3 (WebBrowser). That one looks like it's setting the options for WinInet only.
Electon Posted August 12, 2010 Posted August 12, 2010 is there no solution for this? i really need to change the user agent for an embedded IE control
Electon Posted August 26, 2010 Posted August 26, 2010 (edited) anyone have an example of how to set proxy with this method? Edited August 26, 2010 by Electon
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now