views:

222

answers:

1

How do I ask for an elevation for Registry access to HKLM? I'd like to add EnableLinkedConnections to "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\". I also don't want to use a manifest file. Ive tried the below code but it doesn't seem to help.

RegistryPermission f = new RegistryPermission(
   RegistryPermissionAccess.Create,
   @"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\
   Policies\System\EnableLinkedConnections\1");
f.Demand();

Can anyone tell me what I'm doing wrong please? Thanks

+2  A: 

Use a link demand. Decorate your function with something like:
[SecurityPermissionAttribute(SecurityAction.RequestMinimum, Assertion = true)]

http://msdn.microsoft.com/en-us/library/system.security.permissions.securitypermissionattribute.aspx
http://msdn.microsoft.com/en-us/library/system.security.permissions.securitypermission.aspx

Tangurena