/// <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)); }
/// <summary> /// Returns the root key associated with the current <see cref="RegistryHive"/>. /// </summary> /// <param name="registryHive">Indicator of the top-level key to return.</param> /// <returns>The root <see cref="RegistryKey"/> matching the <see cref="RegistryHive"/>.</returns> public static RegistryKey AsRegistryKey(this RegistryHive registryHive) { var id = HiveMap.GetIdFor(registryHive); return(HiveMap.IsLegalId(id) ? HiveMap.GetKeyById(id) : null); }
/// <summary> /// Returns whether the specified handle is predefined for a hive. /// </summary> /// <param name="hKey">The handle to check.</param> /// <param name="hiveName">The name of the hive matching the handle.</param> /// <returns>True if <paramref name="hKey"/> is a predefined handle.</returns> public static bool IsHiveHandle(uint hKey, out string hiveName) { var id = HiveMap.GetIdFor(hKey); if (HiveMap.IsLegalId(id)) { hiveName = HiveMap.GetNameById(id); return(true); } hiveName = null; return(false); }
/// <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); }
/// <summary> /// Returns the full name of the root key associated with the current <see cref="RegistryHive"/>. /// </summary> /// <param name="registryHive">Indicator of the registry hive which full name must be returned.</param> /// <returns>The full name of the root key matching the <see cref="RegistryHive"/>.</returns> public static string AsRegistryHiveName(this RegistryHive registryHive) { return(HiveMap.GetNameById(HiveMap.GetIdFor(registryHive))); }