コード例 #1
0
        public static void Register(Guid clsid, string exePath, string tlbPath)
        {
            // Register local server
            Trace.WriteLine($"Registering server:");
            Trace.Indent();
            Trace.WriteLine($"CLSID: {clsid:B}");
            Trace.WriteLine($"Executable: {exePath}");
            Trace.Unindent();

            string serverKey = string.Format(KeyFormat.LocalServer32, clsid);

            using RegistryKey regKey = Registry.LocalMachine.CreateSubKey(serverKey);
            regKey.SetValue(null, exePath);

            // Register type library
            TypeLib.Register(tlbPath);
        }
コード例 #2
0
        public static void Register(Guid clsid, string tlbPath)
        {
            Trace.WriteLine($"Registering server with system-supplied DLL surrogate:");
            Trace.Indent();
            Trace.WriteLine($"CLSID: {clsid:B}");
            Trace.Unindent();

            string serverKey = string.Format(KeyFormat.CLSID, clsid);

            // Register App ID - use the CLSID as the App ID
            using RegistryKey regKey = Registry.LocalMachine.CreateSubKey(serverKey);
            regKey.SetValue("AppID", clsid.ToString("B"));

            // Register DLL surrogate - empty string for system-supplied surrogate
            string appIdKey = string.Format(KeyFormat.AppID, clsid);

            using RegistryKey appIdRegKey = Registry.LocalMachine.CreateSubKey(appIdKey);
            appIdRegKey.SetValue("DllSurrogate", string.Empty);

            // Register type library
            TypeLib.Register(tlbPath);
        }
コード例 #3
0
        /// <summary>
        /// Registering server
        /// </summary>
        /// <param name="clsid"></param>
        /// <param name="progId"></param>
        /// <param name="exePath"></param>
        /// <param name="tlbPath"></param>
        /// <param name="perUser"></param>
        static bool Register(Guid clsid, ProgIdAttribute progId, string exePath, string tlbPath, bool perUser)
        {
            // Register local server
            Trace.WriteLine("[Enter]LocalServer.Register");
            Trace.Indent();
            try
            {
                Trace.WriteLine($"CLSID     : {clsid:B}");
                Trace.WriteLine($"progId    : {progId?.Value}");
                Trace.WriteLine($"Executable: {exePath}");
                Trace.WriteLine($"tlbPath   : {tlbPath}");
                Trace.WriteLine($"perUser   : {perUser}");
            }
            finally
            {
                Trace.Unindent();
            }

            RegistryKey dst;

            if (perUser)
            {
                dst = Registry.CurrentUser;
            }
            else
            {
                dst = Registry.LocalMachine;
            }
            Trace.WriteLine(string.Format("Target registory={0}", dst.Name));

            //create "SOFTWARE\Classes\CLSID" if not exists.
            using (var keyClasses = dst.OpenSubKey(KeyFormat.Classes, true))
            {
                const string keyCLSIDName   = "CLSID";
                string       absClassesPath = keyClasses.Name + @"\" + keyCLSIDName;

                if (keyClasses.GetSubKeyNames().Contains(keyCLSIDName))
                {
                    Trace.WriteLine(absClassesPath + " is exists.");
                }
                else
                {
                    Trace.WriteLine(absClassesPath + " is not exists.");
                    using (var keyCLSID = keyClasses.CreateSubKey(keyCLSIDName))
                    {
                        if (keyCLSID == null)
                        {
                            Trace.WriteLine(absClassesPath + " was not created.");
                            return(false);
                        }
                        else
                        {
                            Trace.WriteLine(absClassesPath + " was created.");
                        }
                    }
                }
            }

            {
                string serverKey = string.Format(KeyFormat.formatLocalServer32, clsid);
                using (var regKey = dst.CreateSubKey(serverKey))
                {
                    regKey.SetValue(null, exePath);
                    Trace.WriteLine(string.Format("[Write]\"{0}\" ← \"{1}\"", serverKey, exePath));
                }
            }

            if (progId != null)
            {//Register ProgId
                var progIdKeyName = string.Format(KeyFormat.formatProgIdCLSID, progId.Value);
                using (var keyProgId = dst.CreateSubKey(progIdKeyName))
                {
                    var clsidValue = string.Format("{{{0}}}", clsid);
                    keyProgId.SetValue(null, clsidValue);
                    Trace.WriteLine(string.Format("[Write]{0} ← {1}", keyProgId.Name, clsidValue));
                }
            }
            if ((tlbPath != null) && (tlbPath != ""))
            {
                TypeLib.Register(tlbPath, perUser);
            }
            Trace.WriteLine("[Leave]LocalServer.Register");
            return(true);
        }