SetNamedSecurityInfo (advapi32)
Last changed: anfortas.geo@yahoo.com-216.204.61.86

.
Summary
TODO - a short description

C# Signature:

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

VB Signature:

Declare Function SetNamedSecurityInfo Lib "advapi32.dll" ( _
    ByVal pObjectName As String, _
    ByVal ObjectType As Integer, _
    ByVal SecurityInfo As Integer, _
    ByVal psidOwner As IntPtr, _
    ByVal psidGroup As IntPtr, _
    ByVal pDacl As IntPtr, _
    ByVal pSacl As IntPtr) As Integer

User-Defined Types:

None.

Notes:

Definition from the API

    'DWORD SetNamedSecurityInfo(
    '  LPTSTR pObjectName,
    '  SE_OBJECT_TYPE ObjectType,
    '  SECURITY_INFORMATION SecurityInfo,
    '  PSID psidOwner,
    '  PSID psidGroup,
    '  PACL pDacl,
    '  PACL pSacl
    ');

Tips & Tricks:

Please add some!

Sample Code:

    ' Type of Securable Object we are operating in this sample code
    Private Const SE_FILE_OBJECT = 1&

    ' The Security Information constants required
    Private Const DACL_SECURITY_INFORMATION = 4&

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

    ' 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

    ' write the new Security Descriptor/DACL back
    ret = SetNamedSecurityInfo(strPath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, Nothing, Nothing, pNewDACL, Nothing)
    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