BuildTrusteeWithSid (advapi32)
Last changed: egray1@hot.rr.com-24.26.210.211

.
Summary
TODO - a short description

C# Signature:

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

VB Signature:

    Private Declare Auto Sub BuildTrusteeWithSid Lib "advapi32.dll" ( _
    ByVal pTrustee As IntPtr, _
    ByVal pSid As IntPtr _
    )

User-Defined Types:

TRUSTEE

Notes:

None.

Tips & Tricks:

Please add some!

VB.Net Sample Code:

        Dim Domain, UserName As String
        Dim lenDomain, lenSid, peUse, LastError As Integer
        Dim Win32Error As Win32Exception
        Dim pSID as IntPtr
        Dim t As TRUSTEE

        ' do a "dry run" to get the size of the SID and Domain string
        LookupAccountName(Nothing, _UserName, Nothing, lenSid, Nothing, lenDomain, peUse)
        Domain = Space(lenDomain)
        pSID = Marshal.AllocHGlobal(lenSid)

        ' do it again, for real this time
        If LookupAccountName(Nothing, _UserName, pSID, lenSid, Domain, lenDomain, peUse) = False Then
        LastError = Marshal.GetLastWin32Error()
        Win32Error = New Win32Exception(LastError)
        Throw New Exception(Win32Error.Message)
        End If

        ' Build a trustee
        pTrustee = Marshal.AllocHGlobal(Marshal.SizeOf(t))
        BuildTrusteeWithSid(pTrustee, pSID)

Alternative Managed API:

Do you know one? Please contribute it!

Documentation