Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 349
JimDel Avatar asked Oct 15 '22 13:10

JimDel


1 Answers

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

like image 104
Tangurena Avatar answered Oct 20 '22 15:10

Tangurena