title: How do I register a custom application as a Web Browser in Windows (8.1)?
body: <p>I'm trying to register my own app so it appears in the list for selecting a a default browser in Windows using info I've found <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=vs.85).aspx#sample_web_browser" rel="nofollow noreferrer">around</a> <a href="https://superuser.com/questions/368814/how-do-i-change-my-default-browser-to-an-unlisted-program-in-windows-7">the</a> <a href="https://github.com/nbolton/chweb/blob/master/src-win/Chweb.Launch/Resources/Registry.xml" rel="nofollow noreferrer">internet</a>. The code all runs with no problem, and seems to create the correct registry keys, but my app doesn't show up in the Browser Selection options in Windows 8.1.</p>
  
  <p>I haven't set the <code>UserChoice</code> values shown in some code samples online, as that looks like it'd actually set the default browser (there's only one value), and I'm not trying to do that, only register it as an option.</p>
  
  <p>The relevant code is in RegisterBrowser, but I've included the full class for convenience.</p>
  
  <pre><code>using System;
  using System.Reflection;
  using Microsoft.Win32;
  
  namespace MyApp
  {
      class Program
      {
          const string AppID = "MyApp";
          const string AppName = "My App";
          const string AppDescription = "My App";
          static string AppPath = Assembly.GetExecutingAssembly().Location;
          static string AppIcon = AppPath + ",0";
          static string AppOpenUrlCommand = AppPath + " %1";
          static string AppReinstallCommand = AppPath + " --register";
  
          static void Main(string[] args)
          {
              if (args == null || args.Length != 1 || !HandleArg(args[0]))
                  ShowHelpInfo();
          }
  
          static bool HandleArg(string arg)
          {
              if (string.Equals(arg, "--register", StringComparison.OrdinalIgnoreCase))
                  RegisterBrowser();
              else if (string.Equals(arg, "--unregister", StringComparison.OrdinalIgnoreCase))
                  UnregisterBrowser();
              else if (arg.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || arg.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || arg.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase))
                  LaunchBrowser(arg);
              else
                  return false;
  
              return true;
          }
  
          static void ShowHelpInfo()
          {
              Console.WriteLine("Usage:");
              Console.WriteLine("    MyApp.exe --register               Register as web browser");
              Console.WriteLine("    MyApp.exe --unregister             Unregister as web browser");
              Console.WriteLine("    MyApp.exe \"http://example.org/\"  Launch example.org in specified browser");
          }
  
          static void RegisterBrowser()
          {
              // Register application.
              var appReg = Registry.LocalMachine.CreateSubKey(string.Format("SOFTWARE\\Clients\\StartMenuInternet\\{0}", AppID));
              appReg.SetValue("", AppName);
              appReg.CreateSubKey("DefaultIcon").SetValue("", AppIcon);
              appReg.CreateSubKey("shell\\open\\command").SetValue("", AppOpenUrlCommand);
  
              // Install info.
              var appInstallInfo = appReg.CreateSubKey("InstallInfo");
              appInstallInfo.SetValue("IconsVisible", 1);
              appInstallInfo.SetValue("ShowIconsCommand", AppPath); // TOOD: Do I need to support this?
              appInstallInfo.SetValue("HideIconsCommand", AppPath); // TOOD: Do I need to support this?
              appInstallInfo.SetValue("ReinstallCommand", AppReinstallCommand);
  
              // Register capabilities.
              var capabilityReg = appReg.CreateSubKey("Capabilities");
              capabilityReg.SetValue("ApplicationName", AppName);
              capabilityReg.SetValue("ApplicationIcon", AppIcon);
              capabilityReg.SetValue("ApplicationDescription", AppDescription);
  
              // Set up protocols we want to handle.
              var urlAssoc = capabilityReg.CreateSubKey("URLAssociations");
              urlAssoc.SetValue("http", AppID);
              urlAssoc.SetValue("https", AppID);
              urlAssoc.SetValue("ftp", AppID);
          }
  
          static void UnregisterBrowser()
          {
              Registry.LocalMachine.DeleteSubKeyTree(string.Format("SOFTWARE\\Clients\\StartMenuInternet\\{0}", AppID), false);
          }
  
          static void LaunchBrowser(string arg)
          {
              Console.WriteLine(arg);
              Console.ReadLine();
          }
      }
  }
  </code></pre>