我正在研究文件关联。我已经确定有一个名为UserChoice以下的密钥:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\[ext].
Run Code Online (Sandbox Code Playgroud)
UserChoice只要我创建了该密钥并且Windows尚未创建该密钥,我就能够读取和写入该密钥。但是,如果Windows已经UserChoice创建了该密钥,那么我需要以管理员身份运行才能访问该密钥。我的最终目标是删除密钥。UserChoice
我注意到 Windows在该密钥上放置了拒绝UserChoice规则,这阻止了我删除该密钥。如果我能成功删除该规则,我相信我将能够删除该UserChoice密钥。这是我尝试过的代码:
public static void ShowSecurity(RegistryKey regKeyRoot, string user) {
RegistrySecurity security = regKeyRoot.GetAccessControl(AccessControlSections.All);
foreach (RegistryAccessRule ar in
security.GetAccessRules(true, true, typeof(NTAccount))) {
if (ar.IdentityReference.Value.Contains(User) &&
ar.AccessControlType.ToString().ToLower() == "deny") {
security.RemoveAccessRuleSpecific(ar);
regKeyRoot.SetAccessControl(security);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当 Windows 创建UserChoice密钥时,它会为当前用户添加一条 Type Deny 的安全规则;许可:特殊。该规则不被继承,UserChoice仅适用于密钥。
通过一些混乱并以管理员身份运行,我可以访问它RegistryAccessRule。然而,即使以管理员身份运行,我也无法删除此规则。我在我的研究中读到过,没有一种程序化的方法可以做到这一点。我可以通过 RegEdit 删除此规则。我还可以UserChoice使用 NirSoft 的文件类型管理器删除密钥。所以我认为有某种方法可以做到这一点。
摘要:有没有一种方法可以删除拒绝规则,以便我可以删除密钥UserChoice …