The requested registry access is not allowed # 2

I recently wrote an application that needs access to the following registry key:

HKLM \ SOFTWARE \ Wow6432Node \ Classes \ CLSID

For some odd reason, I am not allowed to access this key on whatever system I have tested on. I am using administrative rights and everything in between to try and accomplish this. I was browsing the first 5 pages of google results and it was still blank.

Notes:

1. Keys that I can delete may or may not contain subsections, I thoroughly tested "DeleteSubKey" and "DeleteSubKeyTree".

2. I tried OpenSubKey ("Key", True) and both false and true values ​​still denied me access.

3. I am also not allowed to access the non-64-bit location (HKLM \ Software \ Classes \ CLSID).

4. I tested this on XP, 7 and 8. XP gave me no problem.

5. The exact error I am getting is below:

The requested registry access is denied. at Microsoft.Win32.RegistryKey.OpenSubKey (rowname, boolean entry)



PLEASE help me ... it killed me in a few days. Any help is appreciated.

+3


source to share


5 answers


   Microsoft.Win32.RegistryKey m_RegEntry = Microsoft.Win32.Registry.LocalMachine;    
   m_RegEntry = m_RegEntry.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\{4D36E96D-E325-11CE-BFC1-08002BE10318}");
        //string 
        int i = 0;
        string[] m_szModemEntries = m_RegEntry.GetSubKeyNames();

      

This brings many connected devices back to the COM port. and a "Properties" entry that we don't need to access.

below I am attaching a simple code to work with it.



            string[] m_szModem;
            Microsoft.Win32.RegistryKey m_RegEntry = Microsoft.Win32.Registry.LocalMachine;
            m_RegEntry = m_RegEntry.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\{4D36E96D-E325-11CE-BFC1-08002BE10318}");
            //string 
            int i = 0;
            string[] m_szModemEntries = m_RegEntry.GetSubKeyNames();
            m_szModem = new string[m_szModemEntries.Length];
            string m_szModemPort = null;
            string m_szModemName = null;
            foreach (string m_szModemEntry in m_szModemEntries)
            {
                if (!IsNumber(m_szModemEntry))
                {
                }
                else
                {
                    m_RegEntry.Close();
                    m_RegEntry = Microsoft.Win32.Registry.LocalMachine;
                    string m_szKeyName = @"SYSTEM\CurrentControlSet\Control\Class\{4D36E96D-E325-11CE-BFC1-08002BE10318}\" + m_szModemEntry;
                    m_RegEntry = m_RegEntry.OpenSubKey(m_szKeyName);
                    m_szModemPort = m_RegEntry.GetValue("AttachedTo").ToString();
                    m_szModemName = m_RegEntry.GetValue("Model").ToString();
                    if (m_szModemName.Contains("<device name>"))
                    {
                        CommPort = m_szModemPort;
                        lbldevicename.Text = "Device connected!";
                        lbldevicename.ForeColor = Color.Green;
                        cmdProgram.Enabled = true;
                        DeviceConnected = true;
                        break;
                    }
                    CommPort = "";
                    cmdProgram.Enabled = false;
                    lbldevicename.Text = "Device not connected!";
                    lbldevicename.ForeColor = Color.Red;
                    DeviceConnected = false;
                }
            }

      

// and the IsNumber function

public Boolean IsNumber(String s)
    {
        foreach (Char ch in s)
        {
            if (!Char.IsDigit(ch)) return false;
        }
        return true;
    }

      

+3


source


You may need to change your access control protection. Use GetAccessControl to get the ACL for a registry key, modify it, and then save it with SetAccessControl .



+1


source


Here's the solution I found that works without admin rights: just leave the parameter "true" and it will read everything. Worked for me!

+1


source


First login with Local Admin account. Then run regedit.exe and click on the registry key you want to edit. From the Edit menu, select Suggestions. Check the permissions of the corresponding user.

I think linked accounts are not allowed to modify the registry key.

0


source


in vb.net you can use this to access the key before doing any operation on it.

x.GetAccessControl(System.Security.AccessControl.AccessControlSections.All)

      

where x is any reg. key

after looking at the code i tried this and it works

  Dim r As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\test", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree)    
           r.DeleteSubKey("subkey", True)

      

0


source







All Articles