CopySid (advapi32)
Last changed: 65.54.188.148

.
Summary
Copies a security identifier (SID) to a buffer.

C# Signature:

[DllImport("advapi32.dll", SetLastError=true)]
static extern bool CopySid(uint nDestinationSidLength, IntPtr pDestinationSid,
   IntPtr pSourceSid);

[DllImport("advapi32.dll", SetLastError=true)]
static extern bool CopySid(uint nDestinationSidLength, byte[] pDestinationSid,
   IntPtr pSourceSid);

VB Signature:

Declare Function CopySid Lib "advapi32.dll" (ByVal nDestinationSidLength As Integer, _
   ByVal pDestinationSid As IntPtr, ByVal pSourceSid As IntPtr) As Boolean

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

    private static byte[] DuplicateSid(IntPtr pSid)
    {
        uint length = UnsafeNativeMethods.GetLengthSid(pSid);
        byte[] bytes = new byte[length];
        UnsafeNativeMethods.CopySid(length, bytes, pSid);
        return bytes;
    }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
CopySid on MSDN