tiw7001 Posted May 10, 2015 Posted May 10, 2015 Hi Guys,I'm having a nightmare trying to set the User Agent in an embedded browser.I have seen examples is several posts that include:a SetUserAgent fuctionUDF NetSession-0.9d.au3Editing a REG KEYI have included my code. I tried using the _SetUserAgent function in UDF Net Session first. No joy. So I commented this out and tried the function (which I renamed SetUserAgent2.I have got urlmon.dll, but it was read,or execute, so I changed this to write, modify, read, execute for system, admin & user. Still no joy.Finally, using the code that tries to write to the REG KEY, just returns "Something went wrong while trying to set the useragent."All suggestions would be grateful received. Many thanks, Tim #include <Constants.au3>#include <Inet.au3>#include <GuiButton.au3>#include <GuiToolBar.au3>#include <GuiConstantsEx.au3>#include <WindowsConstants.au3>#include <IE.au3>#include <NetSession-0.9d.au3> ;~ Local $URL = "http://google.com";~ Local $URL2 = "http://youtube.com";~ Local $sUserAgent = "Agent User 1.0";~ Local $skey = "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings";~ If @OSArch <> "X86" And @AutoItX64 Then $skey = "HKEY_CURRENT_USER64SoftwareMicrosoftWindowsCurrentVersionInternet Settings";~ Local $Write = RegWrite($skey, "User Agent", "REG_SZ", $sUserAgent);~ If Not $Write Then Exit MsgBox(16, "Error!", "Something went wrong while trying to set the useragent.");~ DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0);~ $OIE = _IECREATE("http://whatsmyuseragent.com");~ Sleep (500000);~ _IENAVIGATE($OIE, $URL, 1); sleep(100000) GUICreate("Test User-Agent String", 700, 500);_IEErrorHandlerRegister()$oIE = _IECreateEmbedded()GUICtrlCreateObj($oIE, 10, 10, 680, 480)_SetUserAgent("User-Agent: My super special user agent string.")_IENavigate($oIE,"http://www.useragentstring.com/")sleep(1000)GUISetState()While GUIGetMsg() <> -3WEndFunc _SetUserAgent2($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
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