pSid = Marshal.AllocCoTaskMem(Convert.ToInt32(cbSid));
if (NativeMethods.CreateWellKnownSid(wellKnownSidType, domainSid, pSid, ref cbSid))
{
NativeMethods.ConvertSidToStringSid(pSid, out sidString);
}
Marshal.FreeCoTaskMem(pSid);
return sidString;
}
VB.Net Sample Code:
Private WinWorldSid As Integer = 1
Private SECURITY_MAX_SID_SIZE As Integer = 68
' build a well-known SID for "Everyone"
sidsize = SECURITY_MAX_SID_SIZE
EveryoneSID = Marshal.AllocHGlobal(sidsize)
If CreateWellKnownSid(WinWorldSid, IntPtr.Zero, EveryoneSID, sidsize) = False Then
ret = Marshal.GetLastWin32Error()
Throw New Win32Exception(ret)
End If
Alternative Managed API:
using System.Security.Principal;
var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null).ToString();
Indicates a well-known SID that can be created through CreateWellKnownSid.
4/15/2008 2:26:05 PM - -216.83.2.194
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).