LoginSignup
11
10

More than 5 years have passed since last update.

.NET: カスタムスキーマでデスクトップアプリを起動させる

Last updated at Posted at 2014-04-28


        /// <summary>
        /// URI Schemeのシェルハンドラを登録する
        /// </summary>
        /// <param name="proto">URI Scheme</param>
        /// <param name="path_exe">アプリケーションのパス</param>
        /// <param name="path_icon">アイコンのパス</param>
        public static void RegisterUriSchemeShellHandler(string scheme, string proto, string path_exe = null, string path_icon = null)
        {
            path_exe = path_exe ?? System.Reflection.Assembly.GetExecutingAssembly().Location;
            path_icon = path_icon ?? path_exe;

            var key_proto = Microsoft.Win32.Registry.CurrentUser
                            .CreateSubKey("Software").CreateSubKey("Classes").CreateSubKey(scheme);

            // Protocol Handler
            key_proto.SetValue("", string.Format("URL:{0} Protocol",proto));
            key_proto.SetValue("URL Protocol", "");

            // Icon
            var key_deficon = key_proto.CreateSubKey("DefaultIcon");
            key_deficon.SetValue("", string.Format(@"""{0}""", path_icon));

            // Executable Path
            var key_command = key_proto.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command");
            key_command.SetValue("",
                string.Format(@"""{0}"" ""%1"" ""%2"" ""%3"" ""%4"" ""%5"" ""%6"" ""%7"" ""%8"" ""%9""", path_exe)
                );

        }

メインのWindowsFormで:


        public FormMain()
        {
            InitializeComponent();

            RegisterUriSchemeShellHandler("openid","OpenID");       // "openid://?...." でこのプログラムが呼ばれる
        }    

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10