How do I ask for an elevation for Registry access to HKLM?
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
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
精彩评论