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)?
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
.
You could wrap Process.Start("chrome", url);
it in a try/catch
(catching the exception thrown when browser is not installed)
Kindness,
Dan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With