Skip to content

Instantly share code, notes, and snippets.

@fredrikhaglund
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrikhaglund/21f07cf82ca6ee3c6a63 to your computer and use it in GitHub Desktop.
Save fredrikhaglund/21f07cf82ca6ee3c6a63 to your computer and use it in GitHub Desktop.
How to register a protocol handler in C#
internal static class ChromeLauncher
{
private const string ChromeAppKey = @"\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe";
private static string ChromeAppFileName
{
get
{
return (string) (Registry.GetValue("HKEY_LOCAL_MACHINE" + ChromeAppKey, "", null) ??
Registry.GetValue("HKEY_CURRENT_USER" + ChromeAppKey, "", null));
}
}
public static void OpenLink(string url)
{
string chromeAppFileName = ChromeAppFileName;
if (string.IsNullOrEmpty(chromeAppFileName))
{
throw new Exception("Could not find chrome.exe!");
}
Process.Start(chromeAppFileName, url);
}
}
@fredrikhaglund
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment