Function NTFSPerms($cmd,$object,Optional $trustee,Optional $perms)
Dim $adsu, $sd, $dacl, $ace, $newace
$adsu = CreateObject("ADsSecurityUtility")
If @error Exit @error EndIf
$sd = $adsu.GetSecurityDescriptor($object,1, 1)
$dacl = $sd.DiscretionaryAcl
Select
Case $cmd = "Owner"
? $sd.Owner
Case $cmd = "Count"
? $dacl.AceCount
Case $cmd = "Show"
For Each $Ace in $dacl
? $Ace.Trustee
? $Ace.AceFlags
? $Ace.AccessMask
? $Ace.AceType
? $Ace.Flags
?
Next
Case $cmd = "DEL"
If $trustee <> ""
For Each $ace In $Dacl
If $ace.trustee = $trustee
$Dacl.RemoveAce($Ace)
EndIf
Next
$sd.DiscretionaryAcl = $Dacl
$adsu.SetSecurityDescriptor($object,1,$sd,1)
Else
Exit 1
EndIf
Case $cmd = "ADD"
If $trustee <> ""
$NewAce = CreateObject("AccessControlEntry")
$NewAce.Trustee = $trustee
$NewAce.AceFlags = 3
$NewAce.AccessMask = -1 ;2032127
$NewAce.AceType = 0
$dacl.AddAce($NewAce)
$sd.DiscretionaryAcl = $Dacl
$adsu.SetSecurityDescriptor($object,1,$sd,1)
? @serror
Else
Exit 1
EndIf
Case 1
Exit 1
EndSelect
EndFunction