3

I've recently been writing an application that needs access to the following registry key :

HKLM\SOFTWARE\Wow6432Node\Classes\CLSID

For some odd reason, I'm not allowed access to this key on any system I've tested on. I'm using administrative rights and everything in between to attempt to accomplish this. I've searched through the first 5 Google result pages and still turned up empty.

Things to note :

1. The keys I'm attemping to delete may or may not contain subkeys, I've thoroughly tested "DeleteSubKey" and "DeleteSubKeyTree".

2. I've tried OpenSubKey("Key",True), both false and true values still disallowed me access.

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

4. I've tested this on XP, 7 & 8. XP didn't give me an issue.

5. The exact error I'm receiving can be found below :

Requested registry access is not allowed. at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)



PLEASE help me..this has been killing me for a few days now. Any help is greatly appreciated.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
TL10
  • 31
  • 1
  • 1
  • 3

6 Answers6

3
   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 return many entries connected Devices to COM port . and an entry of "Properties" 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 IsNumber Function

public Boolean IsNumber(String s)
    {
        foreach (Char ch in s)
        {
            if (!Char.IsDigit(ch)) return false;
        }
        return true;
    }
DareDevil
  • 5,249
  • 6
  • 50
  • 88
1

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

xpda
  • 15,585
  • 8
  • 51
  • 82
  • The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation. – Andrew Aug 25 '17 at 14:33
1

Here's a solution I've found which works without Admin rights: just leave out the 'true' paramter, and it will read it all. Worked for me!

roy.me
  • 421
  • 2
  • 7
  • 19
0

First login with Local Admin account. Then run regedit.exe and click on the registry key to be edited. From the Edit menu select premissions. Check the permissions of the related user.

I guess related accounts do not have permission to modify the registry key.

daryal
  • 14,643
  • 4
  • 38
  • 54
  • Thank you for the reply. How would I go about doing this on a remote machine though? I'm applying the application to a slew of systems. All systems I tested on appear to be denying me. – TL10 Jan 19 '13 at 06:57
  • if you can try this on one machine, you may ask for the admins to change the related configuration. do you have remote access (mstsc) to these machines? – daryal Jan 19 '13 at 07:08
  • Sadly I don't have control over the systems. I'm developing the app for a company. Is there a way to gain access to the permissions and edit them through .NET? – TL10 Jan 19 '13 at 07:20
  • I don't think so; but this seems a matter of configuration; thus it is better to talk with their system admin(s) and ask them whether the related access rights have been given or not.. – daryal Jan 19 '13 at 07:23
0

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

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

where x is any reg. key

after seeing your 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)
Arpit
  • 12,767
  • 3
  • 27
  • 40
  • Makes sense.. but if I can't even open the subkey how can I apply the access control? Here's my code : http://pastebin.com/Qdn2vuJP – TL10 Jan 19 '13 at 07:40
  • So you looked at my code and took the wrong registry key? Clearly accessing HKLM isn't my issue. Windows is giving me specific denial to the CLSID key I provided in my link. I appreciate your help though. – TL10 Jan 19 '13 at 16:09
  • i dont have Classes\CLSID\ entry in my registry. i created a test entry in it and it works. – Arpit Jan 19 '13 at 16:35
  • The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation. – Andrew Aug 25 '17 at 14:33
0

Add an app.manifest in Visual studio

add item then search for application manifest file

then Replace the start of it until with this

<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
</requestedPrivileges>
</security>
</trustInfo>
The Sphynx
  • 23
  • 2