Last active
August 29, 2015 14:02
-
-
Save fredrikhaglund/21f07cf82ca6ee3c6a63 to your computer and use it in GitHub Desktop.
How to register a protocol handler in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Part of my blog post How to open a link in another browser.