registry access

P

PiotrKolodziej

Hi
Here is the code:

this.regPath = @"Software\FileManager\" ;

System.Security.Permissions.RegistryPermission permissions =
new
System.Security.Permissions.RegistryPermission(System.Security.Permissions.RegistryPermissionAccess.AllAccess,
@"HKEY_LOCAL_MACHINE\" + regPath);

bool regPermissions =
System.Security.SecurityManager.IsGranted(permissions);

It always returns true. In fact when i try to access registry:



Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath);

key.SetValue("Height", OpenForms.MainForm.Height);

I have got exception:

System.UnauthorizedAccessException: Access to the registry key
'HKEY_LOCAL_MACHINE\Software\FileManager' is denied.


Can anyone help me with that?
 
T

Tom Spink

PiotrKolodziej said:
Hi
Here is the code:

this.regPath = @"Software\FileManager\" ;

System.Security.Permissions.RegistryPermission permissions =
new
System.Security.Permissions.RegistryPermission(System.Security.Permissions.RegistryPermissionAccess.AllAccess,
@"HKEY_LOCAL_MACHINE\" + regPath);

bool regPermissions =
System.Security.SecurityManager.IsGranted(permissions);

It always returns true. In fact when i try to access registry:



Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath);

key.SetValue("Height", OpenForms.MainForm.Height);

I have got exception:

System.UnauthorizedAccessException: Access to the registry key
'HKEY_LOCAL_MACHINE\Software\FileManager' is denied.


Can anyone help me with that?

Hi,

Unfortunately, the code you are using is not testing the type of
access-control you're after. It's testing code access security
permissions. The difference being the type of access control you're after
is, "Is the current user allowed to modify this particular part of the
registry?" and your code is "Is this code allowed to call methods that
modify the registry?"

The answer is: Yes. Your code *is* allowed to call methods that modify the
registry, but as far as the *actual* modifications are concerned, they are
not allowed.

You'll need to take a look at the GetAccessControl() portion of the
RegistryKey class.

Hope this helps,
-- Tom Spink
 

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