tags:

views:

116

answers:

2

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);

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)?

+1  A: 

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

Kindness,

Dan

Daniel Elliott
The problem with this, is that it will launch the browsers if they exist. I need to filter the list without spawning browser.
Danny Tuppeny
D'oy! I haven't had my coffee yet :-(
RB
+2  A: 

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.

Jared Russell
This feels a little dirty, but I'm guessing it's the best way I'm going to find so I'll give it a go. Thanks!
Danny Tuppeny