Change IE user agent

Posted by Ahmed on Stack Overflow See other posts from Stack Overflow or by Ahmed
Published on 2011-01-09T10:49:01Z Indexed on 2011/01/09 10:53 UTC
Read the original article Hit count: 265

Filed under:
|
|
|

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:1.9.2.13) Gecko/20101203 Firefox/3.6.13

With the following code

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/5.9.1.14019)

to

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

Now, the question: 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.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about internet-explorer