views:

359

answers:

4

Hello,

Im currently using ie as an active x com thing on wxWidgets and was wanting to know if there is any easy way to change the user agent that will always work.

Atm im changing the header but this only works when i manually load the link (i.e. call setUrl)

+1  A: 

The only way that will "always work," so far as I've been able to find, is changing the user-agent string in the registry. That will, of course, affect every web browser instance running on that machine.

You might also try a Google search on DISPID_AMBIENT_USERAGENT. From this Microsoft page:

MSHTML will also ask for a new user agent via DISPID_AMBIENT_USERAGENT when navigating to clicked hyperlinks. This ambient property can be overridden, but it is not used when programmatically calling the Navigate method; it will also not cause the userAgent property of the DOM's navigator object or clientInformation behavior to be altered - this property will always reflect Internet Explorer's own UserAgent string.

I'm not familiar with the MSHTML component, so I'm not certain that's helpful.

I hope that at least gives you a place to start. :-)

Head Geek
A: 

Head Geek already told you where in the registy IE will look by default.

This is just a default, though. If you implement IDocHostUIHandler::GetOptionKeyPath or IDocHostUIHandler2::GetOverrideKeyPath, IE will use that registry entry instead.

You'll probably want to use SysInternal's RegMon to debug this.

MSalters
+1  A: 

I did a bit of googling today with the hint you provided head geek and i worked out how to do it.

wxWidgets uses an activex rapper class called FrameSite that handles the invoke requests. What i did was make a new class that inherits from this, handles the DISPID_AMBIENT_USERAGENT event and passes all others on. Thus now i can return a different user agent.

Thanks for the help.

Lodle
Great -- I'm glad it helped!
Head Geek
A: 

I 'm trying change the UserAgent of IE,too.