Detecting browsers set in such a way that Process.Start ("chrome") will not be an error

I am trying to allow a user to choose a browser that my application uses to launch URLs. It currently uses the default browser, but some people want to specify a different browser.

I want to show only installed browsers in the list, and I launch them as follows:

Process.Start ("chrome", url);

The problem is that if Chrome is not installed (and in transit), it does not work.

How can I check if this call does not end without calling it (so that I can pre-filter my list and remove chrome if it does not work)?

+4
source share
2 answers

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

Once you have the registry keys for each browser, you can get the Path value of each key and see if the executable exists at the specified path.

It should be noted that on 64-bit versions of Windows, 32-bit applications are listed in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths .

+4
source

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

Kindness,

Dan

+1
source

All Articles