SetEntriesInAcl (advapi32)
Last changed: -81.255.210.187

.
Summary
TODO - a short description

C# Signature:

[DllImport("advapi32.dll", SetLastError=true)]
static extern int SetEntriesInAcl(
    int cCountOfExplicitEntries,
    ref EXPLICIT_ACCESS pListOfExplicitEntries,
    IntPtr OldAcl,
    out IntPtr NewAcl);

VB Signature:

Declare Function SetEntriesInAcl Lib "advapi32.dll" (( _
    ByVal cCountOfExplicitEntries As Integer, _
    ByRef pListOfExplicitEntries As EXPLICIT_ACCESS, _
    ByVal OldAcl As IntPtr, _
    ByRef NewAcl As IntPtr) As Integer

User-Defined Types:

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=4)> _
    Public Structure EXPLICIT_ACCESS
    Dim grfAccessPermissions As Integer
    Dim grfAccessMode As Integer
    Dim grfInheritance As Integer
    Dim Trustee As Trustee
    End Structure

Notes:

Definition from the API

    'DWORD SetEntriesInAcl(
    '  ULONG cCountOfExplicitEntries,
    '  PEXPLICIT_ACCESS pListOfExplicitEntries,
    '  PACL OldAcl,
    '  PACL* NewAcl
    ');

Tips & Tricks:

Please add some!

Sample Code:

    Private Const SET_ACCESS = 2&
    ' Inheritance Flags
    Private Const CONTAINER_INHERIT_ACE = &H2
    Private Const OBJECT_INHERIT_ACE = &H1

    Dim pNewDACL, pOldDACL As IntPtr
    Dim ea As EXPLICIT_ACCESS
    Dim Win32Error As Win32Exception
    Dim ret, iPerm As Integer

    ' build an explicit access structure
    BuildExplicitAccessWithName(ea, strUserName, iPerm, SET_ACCESS, CONTAINER_INHERIT_ACE Or OBJECT_INHERIT_ACE)

    ' merge this Explict Access with the existing DACL
    ret = SetEntriesInAcl(1, ea, pOldDACL, pNewDACL)
    If ret <> 0 Then
        Win32Error = New Win32Exception(ret)
        Throw New Exception(Win32Error.Message)
    End If

Alternative Managed API:

Do you know one? Please contribute it!

Documentation