Cambiar el agente de usuario de IE

I'm using WatiN to automate Internet Explorer, and so far it's been great. However, I would really like to be able to change the user agent of IE so the server thinks it's actually Firefox or some other browser.

A Firefox useragent string look something like:

Mozilla / 5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko / 20101203 Firefox / 3.6.13

Con el siguiente código

RegistryKey ieKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent");
            ieKey.SetValue("", "Mozilla/5.0");
            ieKey.SetValue("Compatible", "Windows");
            ieKey.SetValue("Version", "U");
            ieKey.SetValue("Platform", "Windows NT 5.1; en-US");
            ieKey.DeleteSubKeyTree("Post Platform");

I have been able to change the IE useragent string from

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; AskTbMP3R7/


Mozilla/4.0 (Windows; U; Windows NT 6.1; Trident/4.0; en-US; rv:

Ahora, la pregunta: how do I delete the Trident/4.0 part and add the "Gecko/20101203 Firefox/3.6.13" part after the parentheses?

I would really like to do this programatically in C#, without using any IE add-ons.

Gracias de antemano.

preguntado el 09 de enero de 11 a las 10:01

Check the comment to the 2nd answer :D -

2 Respuestas

There's no supported way to do this in C# without any IE Addons unless the WebBrowser control is running in-proc, in which case you can use the UrlMkSetSessionOption() API. Ver The User-Agent String: Use and Abuse

Si está dispuesto a usar add-ons, Consulte

Now, there's an sin soporte hack to do this that I wouldn't recommend-- namely, you could replace the COMPATIBLE string with the remainder of the Firefox UA, Seguido de un CRLF and the text IGNORE:. This would cause the HTTP header to "wrap" into a new header, so you'd be sending Headers that look something like:

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko/20101203 Firefox/3.6.13 IGNORE: MSIE 8.0; Windows NT 6.1; Trident/4.0; AskTbMP3R7/

Respondido 26 Feb 17, 20:02

Thank you for your answer, I have already done something which makes the useragent look like the following: Mozilla/5.0 (compatible; MSIE 8.0; X11; U; Linux i686; en-US; rv:1.9.1a2pre) (Gecko/2008073000 Shredder/3.0a2pre ThunderBrowse/ ; Trident/4.0). You can clearly see the bracket before Gecko which usually doesn't appear, but hopefully this will be enough for my needs. I will also try the methods suggested by you. Thanks! - Ahmed

I can't imagine why you'd want to do this. It's not uncommon for otros browsers to need to pretend to be IE due to brain-dead sites that still insist on blocking anything else, but I've never heard of anyone wanting to do it the other way round. At least not in the last ten years or so.

Anyway, as you've already found, it's not as easy to do with IE as it is with other browsers.

If you really want to do this, my suggestion would be to go through a proxy, and have that send the spoofed user agent for you. That ought to be relatively easy to write in any language. You can run the proxy on the local machine where the browser is, and it'll all be transparent to both the browser user and the web site (being on the local machine, even the IP address will be correct, which can be a problem for remote proxies)

For what it's worth, some anti-virus/anti-malware apps actually do this already, having options to block the user agent and referral data to prevent sites from tracking them. As far as I know, they use pretty much exactly this tecnique (those same local proxies are also used to filter out the malware before it gets to the browser).

Respondido el 10 de enero de 11 a las 19:01

Thanks for your answer too. The reason I am doing this is I am sometimes managing a few accounts of an online game I play - and the game checks IPs, useragents, cookies to check are the accounts managed by the same player. I wouldn't really like to get detected so I thought I could make a useragent changer in my application. - Ahmed

We ran into this where a customer site hadn't updated the desktop version of their page, but the mobile version was fine. They weren't planning on updating the desktop for a while, so we had to force the browser into a fake mobile mode to get the better website version to appear. - firebellys

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.