private RegistryDataItem ReadItem(string key, string value) { var data = Registry.GetValue(key, value, null); var original = new RegistryDataItem { Key = key, Value = value, Data = data }; return(original); }
private bool TryDelete(RegistryDataItem item) { var success = false; try { if (IsHiveAvailable(item)) { var keyWithoutRoot = item.Key.Substring(item.Key.IndexOf('\\') + 1); using (var key = RootKey.OpenSubKey(keyWithoutRoot, true)) { if (key.GetValue(item.Value) != null) { key.DeleteValue(item.Value); logger.Debug($"Successfully deleted registry item {item}."); } else { logger.Debug($"No need to delete registry item {item} as it does not exist."); } success = true; } } else { logger.Warn($"Cannot delete item {item} as its registry hive is not available!"); } } catch (Exception e) { logger.Error($"Failed to delete registry item {item}!", e); } return(success); }
private bool TrySet(RegistryDataItem item) { var success = false; try { if (IsHiveAvailable(item)) { Registry.SetValue(item.Key, item.Value, item.Data); logger.Debug($"Successfully set registry item {item}."); success = true; } else { logger.Warn($"Cannot set item {item} as its registry hive is not available!"); } } catch (Exception e) { logger.Error($"Failed to set registry item {item}!", e); } return(success); }
protected abstract bool IsHiveAvailable(RegistryDataItem item);