Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the key from the Registry.
        /// </summary>
        private static void UnregisterKey([NotNull] RegistryKeyXml key, [NotNull] IDictionary <string, string> macros)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (macros == null)
            {
                throw new ArgumentNullException("macros");
            }
            try
            {
                string      sKeyPath   = SubstituteMacros(macros, key.Key);
                RegistryKey regkeyRoot = GetWindowsRegistryRootKey(key.Hive);

                using (RegistryKey regkey = regkeyRoot.OpenSubKey(sKeyPath, false))
                {
                    if (regkey == null)
                    {
                        return;                         // No key, nothing to delete
                    }
                }
                regkeyRoot.DeleteSubKeyTree(sKeyPath);                 // Must do a check because this function will throw if there is no key
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format("Failed to process the key {0}. {1}", key, ex.Message), ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the key to the Registry.
        /// </summary>
        private static void RegisterKey([NotNull] RegistryKeyXml key, [NotNull] IDictionary <string, string> macros)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (macros == null)
            {
                throw new ArgumentNullException("macros");
            }
            try
            {
                string      sPath      = SubstituteMacros(macros, key.Key);
                RegistryKey regkeyRoot = GetWindowsRegistryRootKey(key.Hive);

                using (regkeyRoot.CreateSubKey(sPath))
                {
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format("Failed to process the key {0}. {1}", key, ex.Message), ex);
            }
        }