BuildExplicitAccessWithName (advapi32)
Last changed: -217.167.155.117

.
Summary
TODO - a short description

C# Signature:

[DllImport("advapi32.dll", SetLastError=true)]
static extern TODO BuildExplicitAccessWithName(TODO);

VB Signature:

Declare Function BuildExplicitAccessWithName Lib "advapi32.dll" ( _
    ByRef pExplicitAccess As EXPLICIT_ACCESS, _
    ByVal pTrusteeName As String, _
    ByVal AccessPermissions As Integer, _
    ByVal AccessMode As Short, _
    ByVal Inheritance As Integer)

User-Defined Types:

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=4)> _
    Public Structure TRUSTEE
    Dim pMultipleTrustee As Integer ' must be null, so no need for IntPtr
    Dim MultipleTrusteeOperation As Integer
    Dim TrusteeForm As Integer
    Dim TrusteeType As Integer
    Dim ptstrName As String
    End Structure

    <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

    'VOID BuildExplicitAccessWithName(
    '  PEXPLICIT_ACCESS pExplicitAccess,
    '  LPTSTR pTrusteeName,
    '  DWORD AccessPermissions,
    '  ACCESS_MODE AccessMode,
    '  DWORD Inheritance
    ');

Tips & Tricks:

Please add some!

Sample Code:

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

    ' get the Security Descriptor and DACL
    ret = GetNamedSecurityInfo(strPath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, Nothing, Nothing, pOldDACL, Nothing, pSecDesc)
    If ret <> 0 Then
        Win32Error = New Win32Exception(ret)
        Throw New Exception(Win32Error.Message)
    End If

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

Alternative Managed API:

Do you know one? Please contribute it!

Documentation