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.
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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With