registry permissions

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
 
M

Mr. Arnold

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
W

Willy Denoyette [MVP]

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.
 
C

Colin Priest

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top