Can't delete Registry.LocalMachine subkey

P

Peri

I can delete RCan't delete Registry.LocalMachine
subkeyegistry.LocalMachine subkey using regedit. But not using
code:
RegistryKey eurotaxKey =
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Firm\Application\Eurotax");
eurotaxKey.DeleteSubKey("pathDat");

I am administrator and regedit shows me that 'Administrators' have full
control
on Eurotax key. I've also given 'All users' full control to this key and
still I get System.UnauthorizedException with message "Cannot write to the
registry key".

There's no problem deleting from Registry.CurrentUser.
 
G

Guest

It may be to do with the CLR permissions that have been set.
What is the application type (web app/winform/service)
 
W

Willy Denoyette [MVP]

I can delete RCan't delete Registry.LocalMachine
subkeyegistry.LocalMachine subkey using regedit. But not using
code:
RegistryKey eurotaxKey =
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Firm\Application\Eurotax");
eurotaxKey.DeleteSubKey("pathDat");

I am administrator and regedit shows me that 'Administrators' have full
control
on Eurotax key. I've also given 'All users' full control to this key and
still I get System.UnauthorizedException with message "Cannot write to the
registry key".

There's no problem deleting from Registry.CurrentUser.

--
Peri



As I said in another reply you need to call OpenSubKey with the Writable flag set to true
like this:

Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Firm\Application\Eurotax", true);

Willy.
 
W

Willy Denoyette [MVP]

Ciaran O''Donnell said:
It may be to do with the CLR permissions that have been set.
What is the application type (web app/winform/service)

Not at all, System.UnauthorizedException "Cannot write to the
registry key", is a Windows permission issue not a code access issue.

Willy.
 

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