Registry Access Help
When I press a button my program attempts to give full control of a registry key to the group everyone, the registry key has denied rights so you can't modify it which is the point of the program. When I try to press the button with the program run as administrator I get this error: Requested registry access is not allowed. Heres the coding for the button:
Code:
private void btnFixReg_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtChangeKey.Text))
{
MessageBox.Show("Please enter a key!", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (txtChangeKey.Text.Length < 44 || txtChangeKey.Text.Length > 44)
{
MessageBox.Show("Invalid key format entered!", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (txtChangeKey.Text.Contains(" "))
{
MessageBox.Show("Your entered key contains spaces!", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string enteredkey = txtChangeKey.Text;
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", true);
if (key == null)
{
MessageBox.Show("ArmA 2 Operation Arrowhead is not installed!", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
RegistryKey key7 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", true);
RegistrySecurity userSecurity = new RegistrySecurity();
RegistryAccessRule userRule = new RegistryAccessRule("Everyone", RegistryRights.FullControl, AccessControlType.Allow);
userSecurity.AddAccessRule(userRule);
byte[] buffer2 = new byte[15];
string[] strArray2 = enteredkey.Split(new char[] { '-' });
int upperBound = strArray2.GetUpperBound(0);
byte[] buffer3 = new byte[upperBound + 1];
int num3 = upperBound;
for (int i = 0; i <= num3; i++)
{
buffer3[i] = Convert.ToByte(strArray2[i], 0x10);
}
buffer2 = buffer3;
key.SetValue("KEY", buffer2);
RegistryKey key2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", true);
byte[] objectValue = (byte[])RuntimeHelpers.GetObjectValue(key.GetValue("KEY"));
string str2 = BitConverter.ToString(objectValue);
byte[] buffer = (byte[])RuntimeHelpers.GetObjectValue(key.GetValue("KEY"));
string str3 = BitConverter.ToString(buffer);
str3 = BitConverter.ToString(objectValue);
RegistryKey key5 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", true);
byte[] buffer5 = (byte[])Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Bohemia Interactive Studio\ArmA 2 OA", "Key", null);
string str = BitConverter.ToString(buffer5);
MessageBox.Show("Your registry has been fixed and your ArmA 2 Operation Arrowhead Key has been set to: " + (enteredkey), "Success:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
}
}
}


)
)