By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,050 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,050 IT Pros & Developers. It's quick & easy.

SecurityException

P: n/a
I'm trying to run a modified version of the example in this Microsoft
article:
http://msdn.microsoft.com/library/de...sekeytopic.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\Wi ndows" 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.Unmanage dCode);

sp.Demand();

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

Anybody got a clue what's wrong and what I can do to fix it?
Sep 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Chuck B" <ch****@shc1.comwrote in message
news:e$**************@TK2MSFTNGP02.phx.gbl...
| I'm trying to run a modified version of the example in this Microsoft
| article:
|
http://msdn.microsoft.com/library/de...sekeytopic.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\Wi ndows" 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.Unmanage dCode);
|
| 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.

Sep 21 '06 #2

P: n/a

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uc**************@TK2MSFTNGP05.phx.gbl...
>
"Chuck B" <ch****@shc1.comwrote in message
news:e$**************@TK2MSFTNGP02.phx.gbl...
| I'm trying to run a modified version of the example in this Microsoft
| article:
|
http://msdn.microsoft.com/library/de...sekeytopic.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\Wi ndows" 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.Unmanage dCode);
|
| 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?
Sep 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.