Exemple #1
0
        /// <summary>
        /// Returns the hive containing the specified <paramref name="keyName"/> as a <see cref="RegistryKey"/>.
        /// </summary>
        /// <exception cref="ApplicationException">
        /// An <see cref="ApplicationException"/> is thrown if the <see cref="RegistryHive"/>
        /// can't be extracted from the specified <paramref name="keyName"/>.
        /// </exception>
        /// <param name="keyName">The full key name. Used to extract the rootkey from.</param>
        /// <param name="subKeyName">The name of the hive's subkey, as specified in <paramref name="keyName"/>.</param>
        /// <returns>The top-level <see cref="RegistryKey"/> of which <paramref name="keyName"/> is a member.</returns>
        public static RegistryHive GetHive(string keyName, out string subKeyName)
        {
            int index = keyName.IndexOf("\\");

            if (index == 0)
            {
                throw new ApplicationException("Can't extract the root key from " + keyName);
            }
            if (index != -1)
            {
                subKeyName = keyName.Substring(index + 1);
                keyName    = keyName.Substring(0, index).ToUpperInvariant();
            }
            else
            {
                subKeyName = null;
            }
            var id = HiveMap.GetIdFor(keyName);

            if (HiveMap.IsLegalId(id))
            {
                return(HiveMap.GetHiveById(id));
            }
            throw new ApplicationException(string.Format("The requested hive \"{0}\" can't be found.", keyName));
        }
Exemple #2
0
        /// <summary>
        /// Returns whether the specified handle is predefined for a hive.
        /// </summary>
        /// <param name="hKey">The handle to check.</param>
        /// <param name="registryHive">The <see cref="RegistryHive"/> matching the handle.</param>
        /// <returns>True if <paramref name="hKey"/> is a predefined handle.</returns>
        public static bool IsHiveHandle(uint hKey, out RegistryHive registryHive)
        {
            var id = HiveMap.GetIdFor(hKey);

            if (HiveMap.IsLegalId(id))
            {
                registryHive = HiveMap.GetHiveById(id);
                return(true);
            }
            registryHive = default(RegistryHive);
            return(false);
        }