Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get UserAgent for user's default browser

I'm making an application that contains a WebBrowser element and I would like to have the application show the useragent for that user's default browser.

I know how to get both the default browser via Registry keys and how to get the user agent for a browser but cannot figure out how to combine the two. Is this possible?

like image 879
Mr Wednesday Avatar asked Nov 13 '22 05:11

Mr Wednesday


1 Answers

What I would do (of course, this is a bit of an overkill here) is to include a web server and request an URL from this web server, thus getting the user agent.

I.e. roughly this would include:

  1. Implement a web server inside the application, e.g. this one
  2. Let the WebBrowser control call a local URL of the webserver (e.g. http://127.0.0.1:48384/test)
  3. In the web server's request handler, store the user agent into a variable
  4. Show this variable to the end user (e.g. in a Label control on your WinForm app or simply by sending a response back from the webserver.

I've successfully used the web server inside my applications several times. One example would by my HTML edit control over at the Code Project.

like image 57
Uwe Keim Avatar answered Dec 21 '22 22:12

Uwe Keim