[英]Failed to change owner to “Administrator” for a registry key from “System”
The keys that I am interested are under 我感兴趣的键在
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\PnpLockdownFiles HKEY_LOCAL_MACHINE \\ SOFTWARE \\微软\\的Windows \\ CurrentVersion \\ SETUP \\ PnpLockdownFiles
These keys give full access to system user, and only read access to administrator. 这些密钥授予系统用户完全访问权限,而只有管理员具有读取权限。 I am logged in administrator account.
我已登录管理员帐户。 I am using 2012 R2.
我正在使用2012 R2。
I can change the owner through regedit by 我可以通过regedit更改所有者
right click -> Advanced -> Change onwer -> type "Administrator" -> OK -> Apply
Here are the API in c# that I have tried. 这是我尝试过的c#中的API。 Both failed as access denied
两者均因访问被拒绝而失败
key = Registry.LocalMachine.OpenSubKey(test, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.TakeOwnership);
RegistrySecurity rs = new RegistrySecurity();
rs.SetOwner(new NTAccount("Administrator"));// Set the securitys owner to be Administrator
key.SetAccessControl(rs);
Also tried win32 APIs: 还尝试了win32 API:
SetSecurityInfo(getRegistryKeyHandle(key), SE_OBJECT_TYPE.SE_REGISTRY_KEY, SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION, ownerSid, groupSid, dacl, sacl);
Thanks to @HarryJohnston. 感谢@HarryJohnston。 Your method works.
您的方法有效。
I first enable SeTakeOwnershipPrivilege , then I'm able to take owner with my code. 我首先启用了SeTakeOwnershipPrivilege ,然后可以将代码带给所有者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.