Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting browsers installed so Process.Start("chrome") won't error

Tags:

browser

c#

.net

I'm trying to let the user choose the browser my application uses to launch urls. Currently it uses the default browser, but some people want to specify a different browser.

I'd like to show only installed browsers in the list, and I'm launching them like this:

Process.Start("chrome", url); (more info)

The problem is, if Chrome isn't installed (and in the path), it'll fail.

How can I check whether this call will fail, without calling it (so I can pre-filter my list, and remove chrome if it's not going to work)?

like image 548
Danny Tuppeny Avatar asked Dec 11 '09 12:12

Danny Tuppeny


2 Answers

In Windows all of the installed applications have a key in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths registry key. One solution would be to iterate over all the entries in this key and see if they match the names of your supported browsers.

Once you've got the registry keys for each browser, you can then get the Path value of each key, and see if the executable file exists in the specified path.

One thing to note is that on 64-bit versions of Windows, 32-bit apps are listed in the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths.

like image 88
Jared Russell Avatar answered Sep 20 '22 01:09

Jared Russell


You could wrap Process.Start("chrome", url); it in a try/catch (catching the exception thrown when browser is not installed)

Kindness,

Dan

like image 21
Daniel Elliott Avatar answered Sep 22 '22 01:09

Daniel Elliott