public bool DeleteSubKey(string path, RegistryHive registryHive) { try { using (var regKey = RegistryExtensions.OpenRegistry(registryHive)) regKey.DeleteSubKeyTree(path); return(true); } catch (Exception) { return(false); } }
public bool CreateSubKey(string path, RegistryHive registryHive) { try { RegistryExtensions.OpenRegistry(registryHive) .CreateSubKey(path, RegistryKeyPermissionCheck.Default); return(true); } catch (Exception) { return(false); } }
public bool DeleteValue(string path, RegistryHive registryHive, string name) { try { using (var rootKey = RegistryExtensions.OpenRegistry(registryHive)) using (var subKey = rootKey.OpenSubKey(path, true)) subKey.DeleteValue(name, true); return(true); } catch (Exception) { return(false); } }
public bool CreateValue(string path, RegistryHive registryHive, RegistryValue registryValue) { try { using (var rootKey = RegistryExtensions.OpenRegistry(registryHive)) using (var subKey = rootKey.OpenSubKey(path, true)) subKey.SetValue(registryValue.Key, registryValue.ValueObject); return(true); } catch (Exception) { return(false); } }
public List <RegistrySubKey> GetRegistrySubKeys(string path, RegistryHive registryHive) { try { using ( var regKey = RegistryExtensions.OpenRegistry(registryHive) .OpenSubKey(path, RegistryKeyPermissionCheck.ReadSubTree)) { var subKeys = new List <RegistrySubKey>(); foreach (var subKeyName in regKey.GetSubKeyNames()) { var isEmpty = false; try { using (var subKey = regKey.OpenSubKey(subKeyName, false)) { isEmpty = subKey.GetSubKeyNames().Length == 0; } } catch (Exception) { } subKeys.Add(new RegistrySubKey { Name = subKeyName, IsEmpty = isEmpty }); } return(subKeys); } } catch (Exception) { return(null); } }
public List <RegistryValue> GetRegistryValues(string path, RegistryHive registryHive) { try { using (var regKey = RegistryExtensions.OpenRegistry(registryHive).OpenSubKey(path, false)) { var valueList = new List <RegistryValue>(); foreach (var valueName in regKey.GetValueNames()) { var kind = regKey.GetValueKind(valueName); switch (kind) { case RegistryValueKind.String: valueList.Add(new RegistryValueString { Key = valueName, Value = (string)regKey.GetValue(valueName, string.Empty) }); break; case RegistryValueKind.ExpandString: valueList.Add(new RegistryValueExpandString { Key = valueName, Value = (string)regKey.GetValue(valueName, string.Empty) }); break; case RegistryValueKind.Binary: valueList.Add(new RegistryValueBinary { Key = valueName, Value = (byte[])regKey.GetValue(valueName, new byte[] {}) }); break; case RegistryValueKind.DWord: valueList.Add(new RegistryValueDWord { Key = valueName, Value = (uint)(int)regKey.GetValue(valueName, 0) }); break; case RegistryValueKind.MultiString: valueList.Add(new RegistryValueMultiString { Key = valueName, Value = (string[])regKey.GetValue(valueName, new string[] {}) }); break; case RegistryValueKind.QWord: valueList.Add(new RegistryValueQWord { Key = valueName, Value = (ulong)(long)regKey.GetValue(valueName, 0) }); break; default: valueList.Add(new RegistryValueUnknown { Key = valueName }); break; } } return(valueList); } } catch (Exception) { return(null); } }