Registry Access Help

Posts 18 of 8 · Page 1 of 1
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);
                    }
                    }
                }
            }

        }
You need to open the sub-key initially like this:
Code:
RegistryKey key7 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", RegistryKeyPremissionsCheck.ReadWriteSubTree, RegistryRights.ChangePermissions | RegistryRights.ReadKey);
See if that works.
Quote Originally Posted by master131 View Post
You need to open the sub-key initially like this:
Code:
RegistryKey key7 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", RegistryKeyPremissionsCheck.ReadWriteSubTree, RegistryRights.ChangePermissions | RegistryRights.ReadKey);
See if that works.
Didn't work, I replaced:
RegistryKey key7 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow643 2Node\Bohemia Interactive Studio\ArmA 2 OA", true);
With: RegistryKey key7 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow643 2Node\Bohemia Interactive Studio\ArmA 2 OA", RegistryKeyPremissionsCheck.ReadWriteSubTree, RegistryRights.ChangePermissions | RegistryRights.ReadKey);
And it's still giving me the error: Requested registry access is not allowed.
Code:
var arma2Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ReadPermissions | RegistryRights.ChangePermissions);
            
if (arma2Key != null)
{
    var userRule = new RegistryAccessRule("Everyone", RegistryRights.FullControl, AccessControlType.Allow);
    var userSecurity = arma2Key.GetAccessControl();
    userSecurity.AddAccessRule(userRule);
    arma2Key.SetAccessControl(userSecurity);
}
Just tried that and it worked.

Quote Originally Posted by master131 View Post
Code:
var arma2Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ReadPermissions | RegistryRights.ChangePermissions);
            
if (arma2Key != null)
{
    var userRule = new RegistryAccessRule("Everyone", RegistryRights.FullControl, AccessControlType.Allow);
    var userSecurity = arma2Key.GetAccessControl();
    userSecurity.AddAccessRule(userRule);
    arma2Key.SetAccessControl(userSecurity);
}
Just tried that and it worked.

It's giving me the same error: Requested registry access is not allowed.
Here's the details:
Code:
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Security.SecurityException: Requested registry access is not allowed.
   at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
   at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
   at DayZ_Key_Stealer_Fixer.Form1.btnFixReg_Click(Object sender, EventArgs e) in c:\Users\Michael\Desktop\C# Projects\DayZ Key Stealer Fixer\DayZ Key Stealer Fixer\Form1.cs:line 50
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The Zone of the assembly that failed was:
MyComputer


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
DayZ Key Stealer Fixer
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Michael/Desktop/C%23%20Projects/DayZ%20Key%20Stealer%20Fixer/DayZ%20Key%20Stealer%20Fixer/bin/Debug/DayZ%20Key%20Stealer%20Fixer.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Quote Originally Posted by Jim Morrison View Post
Requested registry access is not allowed.
Run the program as Administrator ?
(To gain editing permissions for it )

By building it, then go to the Projects folder.
>Run it from there?

Or is that what you tried?
-------------------------------

Hmm, seems you have some administrator rights problems then O,o
-Sorry for not taking time to read it all before answering.
(Just woke up so )


Try to use it on some other PC, create a fake registry value, and text
Quote Originally Posted by Jorndel View Post


Run the program as Administrator ?
(To gain editing permissions for it )

By building it, then go to the Projects folder.
>Run it from there?

Or is that what you tried?
-------------------------------

Hmm, seems you have some administrator rights problems then O,o
-Sorry for not taking time to read it all before answering.
(Just woke up so )


Try to use it on some other PC, create a fake registry value, and text
I can edit registry keys fine, just when I deny access to the registry key then attempt to use the program to unlock it it crashes.
Posts 18 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?