SecurityException

  • Thread starter Thread starter Chuck B
  • Start date Start date
C

Chuck B

I'm trying to run a modified version of the example in this Microsoft
article:
http://msdn.microsoft.com/library/d...n32registrykeyclassopenremotebasekeytopic.asp

The only changes I've made to the code is that instead of using
"HKEY_CURRENT_USER\Environment" as my registry path I'm using
"HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows" and setting
OpenRemoteBaseKey to open RegistryHive.LocalMachine instead of the
CurrentUser.

The problem is that I keep getting a SecurityException. I've tried inserting
the code below inside the try block but with no apparent effect

// ****************************

SecurityPermission sp =

new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

sp.Demand();

// ****************************

Anybody got a clue what's wrong and what I can do to fix it?
 
| I'm trying to run a modified version of the example in this Microsoft
| article:
|
http://msdn.microsoft.com/library/d...n32registrykeyclassopenremotebasekeytopic.asp
|
| The only changes I've made to the code is that instead of using
| "HKEY_CURRENT_USER\Environment" as my registry path I'm using
| "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows" and setting
| OpenRemoteBaseKey to open RegistryHive.LocalMachine instead of the
| CurrentUser.
|
| The problem is that I keep getting a SecurityException. I've tried
inserting
| the code below inside the try block but with no apparent effect
|
| // ****************************
|
| SecurityPermission sp =
|
| new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
|
| sp.Demand();
|
| // ****************************
|
| Anybody got a clue what's wrong and what I can do to fix it?
|
|

Your problem is windows security related not CAS rlated.
You must run your code while impersonating a "remote system" administrator,
only administrators can access HKLM.

Willy.
 
Willy Denoyette said:
| I'm trying to run a modified version of the example in this Microsoft
| article:
|
http://msdn.microsoft.com/library/d...n32registrykeyclassopenremotebasekeytopic.asp
|
| The only changes I've made to the code is that instead of using
| "HKEY_CURRENT_USER\Environment" as my registry path I'm using
| "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows" and setting
| OpenRemoteBaseKey to open RegistryHive.LocalMachine instead of the
| CurrentUser.
|
| The problem is that I keep getting a SecurityException. I've tried
inserting
| the code below inside the try block but with no apparent effect
|
| // ****************************
|
| SecurityPermission sp =
|
| new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
|
| sp.Demand();
|
| // ****************************
|
| Anybody got a clue what's wrong and what I can do to fix it?
|
|

Your problem is windows security related not CAS rlated.
You must run your code while impersonating a "remote system"
administrator,
only administrators can access HKLM.

Willy.

Ok thanks. Does it make any difference that I set myself as a user with
control permissions on every key in the path that I'm trying to access?
 

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

Back
Top