Exemple #1
0
        /// <summary>
        /// Регистрирует компонент в реестре.
        /// </summary>
        /// <param name="key">Ключ реестра.</param>
        public static void Register(string key)
        {
            // Open the CLSID\{guid} key for write access
            RegistryKey _key = ComRegisterHelper._OpenSubKey(key);

            try {
                // And create the 'Control' key - this allows it to show up in the ActiveX control container
                _key.CreateSubKey(ComRegisterHelper._controlKey).Close();

                // Next create the CodeBase entry - needed if not string named and GACced.
                RegistryKey _inprocKey = ComRegisterHelper._OpenInprocServer32(_key);
                try {
                    _inprocKey.SetValue(ComRegisterHelper._codebaseKey, Assembly.GetExecutingAssembly().CodeBase);
                } finally {
                    _inprocKey.Close();
                }
            } finally {
                _key.Close(); // Finally close the main key
            }
        }
Exemple #2
0
        /// <summary>
        /// Удаляет регистрацию компонента из реестра.
        /// </summary>
        /// <param name="key">Ключ реестра.</param>
        public static void Unregister(string key)
        {
            // Open HKCR\CLSID\{guid} for write access
            RegistryKey _key = ComRegisterHelper._OpenSubKey(key);

            try {
                // Delete the 'Control' key, but don't throw an exception if it does not exist
                _key.DeleteSubKey(ComRegisterHelper._controlKey, false);

                // Next open up InprocServer32
                RegistryKey _inprocKey = ComRegisterHelper._OpenInprocServer32(_key);
                try {
                    // And delete the CodeBase key, again not throwing if missing
                    _inprocKey.DeleteSubKey(ComRegisterHelper._codebaseKey, false);
                } finally {
                    _inprocKey.Close();
                }
            } finally {
                _key.Close(); // Finally close the main key
            }
        }