bool ExecuteDeleteValue() { try { string keyName = RegistryUtils.NormalizeHive(Params[PARAM_NAME_KEY]); //checkign if it is at all there, because if it is not //or the keys in path are not, the subsecuent code would create those if (this.CheckStatus() != StatusResult.Match) { //create the key, or open it if already there //the 64 view allows to always go to main branch(on 32 bit OS it means 32 bit view) using (RegistryKey theKey = RegistryUtils.CreateOrOpenRegistryKey(keyName, RegistryView.Registry64)) { //check if value name and data is available if (Params.TryGetValue(PARAM_NAME_VALUE, out string valueName)) { theKey.DeleteValue(valueName, false); } } } return(true); } catch (Exception ex) { Log.Error("RegistryAction.ExecuteDeleteValue", ex.ToString()); return(false); } }
bool ExecuteAdd() { try { string keyName = RegistryUtils.NormalizeHive(Params[PARAM_NAME_KEY]); //create the key, or open it if already there using (RegistryKey theKey = RegistryUtils.CreateOrOpenRegistryKey(keyName, RegistryView.Registry64)) { //check if value name and data is available if (Params.TryGetValue(PARAM_NAME_VALUE, out string valueName) && Params.TryGetValue(PARAM_NAME_DATA, out string data)) { Params.TryGetValue(PARAM_NAME_TYPE, out string type); var valueKind = RegistryUtils.String2RegistryValueKind(type); if (RegistryUtils.TryParseRegValueData(data, valueKind, out object dataVal)) { theKey.SetValue(valueName, dataVal, valueKind); } else { throw new Exception($"Wrong data for registry value of type: {type}"); } } } return(true); } catch (Exception ex) { Log.Error("RegistryAction.ExecuteAdd", ex.ToString()); return(false); } }