[DllImport("advapi32.dll", SetLastError=true)]
static extern TODO GetExplicitEntriesFromAcl(TODO);
Declare Auto Function GetExplicitEntriesFromAcl Lib "AdvAPI32.DLL" ( _
ByVal pacl As IntPtr, _
ByRef pcCountOfExplicitEntries As Integer, _
ByRef pListOfExplicitEntries As IntPtr _
) As Integer
None.
'DWORD GetExplicitEntriesFromAcl(
' PACL pacl,
' PULONG pcCountOfExplicitEntries,
' PEXPLICIT_ACCESS* pListOfExplicitEntries
');
Please add some!
Dim pSecDesc, pDACL, ACE_ptr, iPtr, StringPtr As IntPtr
Dim i, num, Ptr_num As Integer
Dim SidString, NameBuf As String
' get the Security Descriptor and DACL
If GetNamedSecurityInfo(Path, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, Nothing, Nothing, pDACL, Nothing, pSecDesc) <> 0 Then
Exit Sub
End If
' Get an array of ACEs
If GetExplicitEntriesFromAcl(pDACL, num, ACE_ptr) <> 0 Then
Exit Sub
End If
Marshal.FreeHGlobal(ACE_ptr)
Marshal.FreeHGlobal(pSecDesc)
If you have .NET v2.0:
For Files
System.Security.AccessControl.FileSecurity
For Registry Keys
System.Security.AccessControl.RegistrySecurity
For Directories
System.Security.AccessControl.DirectorySecurity
Sample Code
{
System.Security.AccessControl.FileSecurity secDesc =
new System.Security.AccessControl.FileSecurity(Path,
System.Security.AccessControl.AccessControlSections.Access);
System.Security.AccessControl.AuthorizationRuleCollection aceCollection =
pSecDesc.GetAccessRules(true, false, typeof(System.Security.Principal.NTAccount));
}