How do I use C# to get the path to chrome.exe on Windows?

asp.net, c#, google-chrome

Solution

When Chrome is installed on a computer, it installs the `ChromeHTML` URL protocol. You could use that to get to the path for Chrome.exe.

Some example code may help. The following code returns a string that looks like this:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"

Example code to get that:

var path = Microsoft.Win32.Registry.GetValue(
    @"HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command", null, null) as string;
if (path != null)
{
    var split = path.Split('\"');
    path = split.Length >= 2 ? split[1] : null;
}

if path is null at the end of the code snippet, then you can assume Chrome isn't installed.

Problem

I want to launch chrome from my automated test framework so that I can test my server-side ASP.NET code. What's the best way to determine the location of where chrome.exe is located on my computer?

Original source