all groups > dotnet security > august 2004 >
You're in the

dotnet security

group:

Access to remote registry (RegistryPermissionAttribute)


Access to remote registry (RegistryPermissionAttribute) Marc Wuergler
8/20/2004 3:20:32 PM
dotnet security:
Hi !

I'm trying to access a registry key on a remote computer.

Here is my code :

[RegistryPermissionAttribute(SecurityAction.RequestMinimum, Read =
@"HKEY_LOCAL_MACHINE\SOFTWARE\MyKey")]
public static string ReadRegistryKey(string PsMachineName)
{
try
{
RegistryKey LoKey =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, PsMachineName);
RegistryKey LoSubKey = LoKey.OpenSubKey(@"SOFTWARE\MyKey");
string LsValue = LoSubKey.GetValue("InstallFolder").ToString();

return LsValue;
}
catch(Exception e)
{
return e.Message;
}
}

This code does not compile !!!

Error : Error emitting
'System.Security.Permissions.RegistryPermissionAttribute' attribute --
'Common Language Runtime Internal error: 0x8013143e'


Could anyone tell me what I'm doing wrong or how I can fix this !? Thanks a
lot.

Marc

RE: Access to remote registry (RegistryPermissionAttribute) shawnfa NO[at]SPAM online.microsoft.com (
8/20/2004 10:57:25 PM
Hi Marc,

The problem seems to be that you're emitting assembly-level declarative security onto a method. RequestMinimum can only be done on
a per-assembly basis, so if you add an assembly: qualifier to your attribute, then you should be able to compile the code. As an aside -- what
version of the CLR are you seeing this behavior on?

-Shawn
http://blogs.msdn.com/shawnfa

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they
originated.
--------------------
[quoted text, click to view]

Re: Access to remote registry (RegistryPermissionAttribute) Marc Wuergler
8/23/2004 8:25:41 AM
Hi Shawn !

Thanks for your reply. The version of my clr is 1.1.4322.573.

If I use Demand instead of RequestMinimum, my code compiles. But if I add
assembly:, there is no way to compile.

Now, with that attribute, I can access the registry key only with my domain
user. I used regedt32 to give access rights to a local user of the machine
(it's a user that I created to use with impersonation from my web app). But
even if I give full control access to the registry key, my request is
refused. Do you have any ideas how I could do this ?

Thanks for your reply

Marc



""Shawn Farkas"" <shawnfa@online.microsoft.com> a écrit dans le message de
news:MicfNkwhEHA.304@cpmsftngxa10.phx.gbl...
[quoted text, click to view]
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
..phx.gbl
[quoted text, click to view]

Re: Access to remote registry (RegistryPermissionAttribute) Marc Wuergler
8/23/2004 11:22:42 AM
OK ... I got it ...

To access the registry key with a specific user, I need to give that user
access to the key

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\
SecurePipeServers\winreg

of the remote machine....

""Shawn Farkas"" <shawnfa@online.microsoft.com> a écrit dans le message de
news:MicfNkwhEHA.304@cpmsftngxa10.phx.gbl...
[quoted text, click to view]
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
..phx.gbl
[quoted text, click to view]

AddThis Social Bookmark Button