registry permissions

  • Thread starter Thread starter Colin Priest
  • Start date Start date
C

Colin Priest

I am trying to write a program to switch off serial port enumerations
via the associated registry key. My code is:

RegistryPermission permission = new
RegistryPermission(RegistryPermissionAccess.Write,
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\ACPI\\PNP0501");
permission.Demand();
RegistryKey key =
Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\ACPI\\PNP0501",
true);


But the last line throws a Security Exception saying "Requested
security access is not allowed". What am I doing wrong?

Colin
 
Colin Priest said:
I am trying to write a program to switch off serial port enumerations
via the associated registry key. My code is:

RegistryPermission permission = new
RegistryPermission(RegistryPermissionAccess.Write,
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\ACPI\\PNP0501");
permission.Demand();
RegistryKey key =
Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\ACPI\\PNP0501",
true);


But the last line throws a Security Exception saying "Requested
security access is not allowed". What am I doing wrong?

Does the user account that this program is running under have the
permissions to change the registry node?
 
Colin,

There are two things I can think of. First, the user account you are
running this under doesn't have the appropriate rights to access the
registry key. The second is that you are running the application from a
network share, or from the internet, and as a result, .NET is sandboxing the
application so that it doesn't do any harm.
 
Colin Priest said:
I am trying to write a program to switch off serial port enumerations
via the associated registry key. My code is:

RegistryPermission permission = new
RegistryPermission(RegistryPermissionAccess.Write,
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\ACPI\\PNP0501");
permission.Demand();
RegistryKey key =
Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\ACPI\\PNP0501",
true);


But the last line throws a Security Exception saying "Requested
security access is not allowed". What am I doing wrong?

Colin



You don't have the right to open this key for write access, regular users,
including administrators, can only open this key for reading. This whole
registry tree is owned by the OS device manager, what exactly are you trying
to achieve?

Willy.
 
You don't have the right to open this key for write access, regular users,
including administrators, can only open this key for reading. This whole
registry tree is owned by the OS device manager, what exactly are you trying
to achieve?

Willy.


Thank Willy. As I said above, I am trying to set the registry keys to
stop enumeration of serial devices. I need to do this to stop Windows
incorrectly recognising my serial device as a mouse etc.

The user account full administrator access. What else do I need?
 
Back
Top