项目有个需求,要从网页中打开一个桌面应用程序,故找到Url Protocol,上Code :
应用程序端:
/// <summary>
/// 注册表名称,注意不能有特殊符号,包括下划线
/// </summary>
private const string RegName = "WFA";
public void UpdateProtocol()
{
try
{
if (Registry.ClassesRoot.OpenSubKey(RegName) != null)
{
RegistryKey rg = Registry.ClassesRoot.OpenSubKey(RegName+"\\shell\\open\\command", true);
string
oldUrl = rg.GetValue("").ToString(),
newUrl = string.Format("\"{0}\" \"%1\"", Application.ExecutablePath);
if (!oldUrl.Equals(newUrl, StringComparison.CurrentCultureIgnoreCase))
{
rg.SetValue("", newUrl);
}
}