我想在注册表项中添加ACE,但不会通过子项继承。这是VBScript代码:
Set sdUtil = CreateObject("ADsSecurityUtility")
S = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\XXXX"
Set sd = sdUtil.GetSecurityDescriptor(S, ADS_PATH_REGISTRY, ADS_SD_FORMAT_IID)
Set oldDacl = sd.DiscretionaryAcl
Set dacl = CreateObject("AccessControlList")
dacl.AclRevision = ADS_REVISION_DS
dacl.AceCount = 0
'remove network service ace if it exists
For Each ace In oldDacl
If UCase(ace.trustee) <> "NT AUTHORITY\NETWORK SERVICE" And UCase(ace.trustee) <> "S-1-5-20" Then
ace.AceFlags = ace.AceFlags Or OBJECT_INHERIT_ACE Or CONTAINER_INHERIT_ACE
dacl.AddAce ace
End If
Next
'add the new network service ace
Set ace = CreateObject("AccessControlEntry")
ace.Trustee = "NT AUTHORITY\NETWORK SERVICE"
ace.AccessMask = KEY_ALL_ACCESS
ace.AceFlags = OBJECT_INHERIT_ACE Or CONTAINER_INHERIT_ACE
ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED
dacl.AddAce ace
If (sd.Control And SE_DACL_AUTO_INHERITED) <> 0 Then
sd.Control = sd.Control Or SE_DACL_AUTO_INHERIT_REQ
End If
If (sd.Control And SE_SACL_AUTO_INHERITED) <> 0 Then
sd.Control = sd.Control Or SE_SACL_AUTO_INHERIT_REQ
End If
If (sd.Control And SE_DACL_PROTECTED) <> 0 Then
sd.Control = sd.Control Xor SE_DACL_PROTECTED
End If
ReorderDacl dacl 'This subroutine reorder dacl using w2k rules
sd.DiscretionaryAcl = dacl
ret = sdUtil.SetSecurityDescriptor(S, ADS_PATH_REGISTRY, sd, ADS_SD_FORMAT_IID)
我还使用另一个例程来扫描所有子键并删除除标记为ADS_ACEFLAG_INHERITED_ACE
之外的所有ACE代码执行后,我得到HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ XXXX的子项只继承SYSTEM,Administrators,Everyone&amp;受限制的访问。它们在父键上设置,但NETWORK SERVICE访问权限在HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ XXXX上,但不会传播给子项。
答案 0 :(得分:0)
最后我得知已经存在的子键不会自动获得继承的ace,所以我必须手动和递归地使用ADS_ACEFLAG_INHERITED_ACE或者来自所有子节点添加ace。
尽管文档说ADS_ACEFLAG_INHERITED_ACE是由系统设置的,但也可以手动设置它。