Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Search Results for "SID" in [All]

odbc32

.

    Private Sub OnGetODBCConnectionNames(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbExpSID.DropDown, cmbImpSid.DropDown

user32

.

static extern bool AllowSetForegroundWindow(int dwProcessId);

.

Shared Function AllowSetForegroundWindow(ByVal dwProcessId As Integer) As Boolean

.

This assumes that the AnimateWindow function is declared inside class User32

.

    /// <param name="right">Right most side.</param>

.

    /// <param name="bottom">Bottom most side.</param>

.
.

Inside a Windows Form:

.

            //Optional int ProcessID;

.

            //Optional Win32.GetWindowThreadProcessId(GetForegroundWindow(),out ProcessID)

.

                //Optional if( ProcessID == wordProcess.Id ) return ApplicationState.Focused;

.

Consider System.Windows.Forms.Screen.

.

  Private Const UOI_USER_SID = 4

.

  private const int UOI_USER_SID = 4;

.
Summary
.

static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

.

// When you don't want the ProcessId, use this overload and pass IntPtr.Zero for the second parameter

.

static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);

.

Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, _

.

                          ByRef lpdwProcessId As IntPtr) As UInteger

.

    ''' <param name="lpdwProcessId">A pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not. </param>

.

    Private Declare Auto Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, _

.

                  ByRef lpdwProcessId As Integer) As Integer

.

We can use this API to get ProcessID from Window's Title by combining this function with EnumWindows.

.

  GetWindowThreadProcessId(lngAccessHwnd, lngPid)

.

    Public Declare Auto Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr

.

        Dim iProcessID As IntPtr

.

        GetWindowThreadProcessId(hOwner, iProcessID)

.

        oResult = Process.GetProcessById(iProcessID.ToInt32)

.

IntPtr pID = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);

.

GetWindowThreadProcessId returns the id of the thread that created the target window. To get the process id of a window, use the first c# signature above, and:

.

int processID = 0;

.

int threadID = GetWindowThreadProcessId(hWnd, out processID);

.
Documentation
[GetWindowThreadProcessId] on MSD
.
Workaround
Use GetWindowThreadProcessId to get the process ID, then Process.GetProcessById to retrieve the process information. The resultant System.Diagnostics.Process Object's MainModule Property has the Filename Property, which is the Information you are probably searching.
.
Summary
.

static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

.

// When you don't want the ProcessId, use this overload and pass IntPtr.Zero for the second parameter

.

static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);

.

Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, _

.

                          ByRef lpdwProcessId As Integer) As Integer

.

    ''' <param name="lpdwProcessId">A pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not. </param>

.

    Private Declare Auto Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, _

.

                  ByRef lpdwProcessId As Integer) As Integer

.

We can use this API to get ProcessID from Window's Title by combining this function with EnumWindows.

.

  GetWindowThreadProcessId(lngAccessHwnd, lngPid)

.

    Public Declare Auto Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr

.

        Dim iProcessID As IntPtr

.

        GetWindowThreadProcessId(hOwner, iProcessID)

.

        oResult = Process.GetProcessById(iProcessID.ToInt32)

.

IntPtr pID = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);

.

GetWindowThreadProcessId returns the id of the thread that created the target window. To get the process id of a window, use the first c# signature above, and:

.

int processID = 0;

.

int threadID = GetWindowThreadProcessId(hWnd, out processID);

.
Documentation
[GetWindowThreadProcessId] on MSD
.
Summary
You call the IsHungAppWindow function to determine if Microsoft Windows considers that a specified application is not responding.
.

        /// <param name="resId">Name of the resource icon that should be loaded.

.

        public static Icon GetIconFromExe(string path = null, string resId = "#32512", int size = 32) {

.

            IntPtr ptr = LoadImage(h, resId, 1, size, size, 0);

.

With the enum beepType you get intellisense when you type "beep." and you can then select the kind of beep you want. For dylan.NET, use the fields containing the integer values inside the WinSnd class of dnu.dll at http://dylandotnetapps.codeplex.com/

.

Consider System.Windows.Forms.Screen class and its FromRectangle.

.

Consider System.Windows.Forms.Screen.

.

    /// The rest of the area in rcMonitor contains system windows such as the task bar and side bars.

.

    /// By convention, the right and bottom edges of the rectangle are normally considered exclusive.

.

    /// In other words, the pixel whose coordinates are ( right, bottom ) lies immediately outside of the the rectangle.

.

    /// The rest of the area in rcMonitor contains system windows such as the task bar and side bars.

.

    /// By convention, the right and bottom edges of the rectangle are normally considered exclusive.

.

    /// In other words, the pixel whose coordinates are ( right, bottom ) lies immediately outside of the the rectangle.

.

/// <param name="X">C++ ( X [in]. Type: int )<br />Specifies the new position of the left side of the window.</param>

.

    ''' <param name="X">Specifies the new position of the left side of the window.</param>

.

        Int32 processId

.

    private static extern int GetWindowThreadProcessId(

.

        out Int32 lpdwProcessId

.

        StatusBar.GetWindowThreadProcessId(this._handle, out pid);

.

/** this takes the POINT, which is using screen coords (0,0 in top left screen) and converts them into coords inside specified window (0,0 from  top left of hWnd) **/

.

   [testing.windows]::SetForegroundWindow( @( Get-Process notepad |? { $_.id -in @( get-wmiobject win32_process -filter "name='notepad.exe'" |% { if ( $_.getowner().user -eq $env:username ) { $_.processid } } ) } )[0].MainWindowHandle)

.

    ///     calling the AllowSetForegroundWindow function. The process specified by dwProcessId loses the ability to set

.

    uint foreThread = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);

.

    /// <param name="X">C++ ( X [in]. Type: int )<br />The new position of the left side of the window, in client coordinates.</param>

.

    ///     hwnd and window manager operations are only effective inside a session and cross-session attempts to manipulate

25: TCITEM
.

    uint ProcessID;

.

    GetWindowThreadProcessId((IntPtr)handle, out ProcessID);

.

    ProcessAccessFlags.VMWrite | ProcessAccessFlags.QueryInformation, false, ProcessID);

.

    static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

.

    static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwProcessId);

.

        TRACKMOUSEEVENT tme; // Define it on the outside so you dont recreate it each time the mouse enters

ntdll

.

    public static int GetParentProcessId()

.

        return (int)pbi.InheritedFromUniqueProcessId;

.
Summary
The RtlInitializeSid routine initializes a security identifier (SID) structure.
.

private static extern Int32 RtlInitializeSid([In, Out] ref SID Sid, [In] ref SID_IDENTIFIER_AUTHORITY IdentifierAuthority, byte SubAuthorityCount);

.

Declare Function RtlInitializeSid Lib "ntdll.dll" (TODO) As TODO

.

struct SID_IDENTIFIER_AUTHORITY

.

   public SID_IDENTIFIER_AUTHORITY(byte[] value)

.

struct SID

.

   public SID_IDENTIFIER_AUTHORITY IdentifierAuthority;

.

   public SID(int subAuthorityCount)

.

     this.IdentifierAuthority = default(SID_IDENTIFIER_AUTHORITY);

.

SID_IDENTIFIER_AUTHORITY id = new SID_IDENTIFIER_AUTHORITY(new byte[] { 0, 0, 0, 0, 0, 0 });

.

// new SID with an allocated SubAuthority count of 1

.

SID sid = new SID(1);

.

var status = RtlInitializeSid(ref sid, ref id, (byte)sid.SubAuthority.Length);

.
Documentation
[RtlInitializeSid] on MSDN
.

    SystemLookasideInformation = 0x002D,

.

    SystemProcessIdInformation = 0x0058,

powrprof

.

Hey Marty, I'm not your answering service, but you're outside pouting about the car, Jennifer Parker called you twice. Say that again. Calvin, why do you keep calling me Calvin? Marty, you didn't fall asleep, did you? I'm too loud. I can't believe it. I'm never gonna get a chance to play in front of anybody.

advapi32

.
Summary
The AddAccessAllowedAce function adds an access-allowed access control entry (ACE) to an access control list (ACL). The access is granted to a specified security identifier (SID).
.

static extern bool AddAccessAllowedAce(IntPtr pAcl, uint dwAceRevision, ACCESS_MASK AccessMask, IntPtr pSid);

.

                     pSid As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean

.

    pSid As Long) As Boolean

.
Summary
Allocates and initializes a security identifier (SID) with up to eight subauthorities.
.

static extern bool AllocateAndInitializeSid(

.

    ref SidIdentifierAuthority pIdentifierAuthority,

.

    out IntPtr pSid);

.

Declare Function AllocateAndInitializeSid Lib "advapi32.dll" ( _

.

   ByRef pSid As IntPtr) As Boolean

.

The returned SID must be freed with FreeSid.

.

    public struct SidIdentifierAuthority

.

    SidIdentifierAuthority NtAuthority = new SidIdentifierAuthority();

.

    IntPtr AuthenticatedUsersSid = IntPtr.Zero;

.

    // Get the SID for the Authenticated Uses group

.

    Native.AllocateAndInitializeSid(ref NtAuthority, 1, AuthenticatedUser, 0, 0, 0, 0, 0, 0, 0, out AuthenticatedUsersSid);

.

    // Remember to free the SID when you are done

.

    Native.FreeSid(AuthenticatedUsersSid);

.

    Structure SID_IDENTIFIER_AUTHORITY

.

    Dim NtAuthority As SID_IDENTIFIER_AUTHORITY

.

    If Not AllocateAndInitializeSid(NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, AdminGroup) Then

.

        MsgBox("Yikes, couldn't create the Local Admininstrator Group's SID")

.
Documentation
[AllocateAndInitializeSid] on MSDN
.

private static extern void BuildTrusteeWithSid(ref TRUSTEE pTrustee, IntPtr sid);

.

    Private Declare Auto Sub BuildTrusteeWithSid Lib "advapi32.dll" ( _

.

    ByVal pSid As IntPtr _

.

        Dim lenDomain, lenSid, peUse, LastError As Integer

.

        Dim pSID as IntPtr

.

        ' do a "dry run" to get the size of the SID and Domain string

.

        LookupAccountName(Nothing, _UserName, Nothing, lenSid, Nothing, lenDomain, peUse)

.

        pSID = Marshal.AllocHGlobal(lenSid)

.

        If LookupAccountName(Nothing, _UserName, pSID, lenSid, Domain, lenDomain, peUse) = False Then

.

        BuildTrusteeWithSid(pTrustee, pSID)

.
Documentation
[BuildTrusteeWithSid] on MSDN
.

5    SERVICE_CONFIG_SERVICE_SID_INFO

.

5    SERVICE_CONFIG_SERVICE_SID_INFO

.
Summary
Determines whether a specified SID is enabled in an access token
.

static extern bool CheckTokenMembership(IntPtr TokenHandle, IntPtr SidToCheck, out bool IsMember);

.

    ByVal SidToCheck As IntPtr, _

.

    '  PSID SidToCheck,

.

    Dim NtAuthority As SID_IDENTIFIER_AUTHORITY

.

    ' Next we build the SID for the local Administrators group

.

    If Not AllocateAndInitializeSid(NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, AdminGroup) Then

.

        MsgBox("Yikes, couldn't create the Local Admininstrator Group's SID")

.

    FreeSid(AdminGroup)

. .
Summary
The ConvertSidToStringSid function converts a security identifier (SID) to a string format suitable for display, storage, or transmission.
.

static extern bool ConvertSidToStringSid(

.

    [MarshalAs(UnmanagedType.LPArray)] byte [] pSID,

.

    out IntPtr ptrSid);

.

static extern bool ConvertSidToStringSid(IntPtr pSid, out string strSid);

.

Declare Auto Function ConvertSidToStringSid Lib "advapi32.dll" (ByVal pSID() As Byte, _

.

   ByRef ptrSid As IntPtr) As Boolean

.

public static string GetSidString(byte[] sid)

.

   IntPtr ptrSid;

.

   string sidString;

.

   if (!ConvertSidToStringSid(sid,out ptrSid))

.

     sidString = Marshal.PtrToStringAuto(ptrSid);

.

     LocalFree(ptrSid);

.

   return sidString;

.

// Another C# Sample that converts a sid from a DirectoryEntry object

.

private string GetTextualSID(DirectoryEntry objGroup){

.

  string sSID = string.Empty;

.

  byte[] SID = objGroup.Properties["objectSID"].Value as byte[];

.

  IntPtr sidPtr = Marshal.AllocHGlobal( SID.Length);

.

  sSID = "";

.

  System.Runtime.InteropServices.Marshal.Copy(SID, 0, sidPtr, SID.Length);

.

  ConvertSidToStringSid((IntPtr)sidPtr, ref sSID);

.

  System.Runtime.InteropServices.Marshal.FreeHGlobal( sidPtr );

.

  return sSID;}

.

Public Shared Function ByteArrayToStringSid(ByRef bArray As Byte()) As String

.

   Dim ptrSID As IntPtr = Nothing

.

     Dim sSID As String = String.Empty

.

     If ConvertSidToStringSid(bArray, ptrSID) = True Then

.

       'ConvertSidToStringSid DllImport.  The default is CharSet.Ansi.

.

       sSID = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptrSID)

.

     Return sSID

.

     LocalFree(ptrSID)

.

Public Shared Function ByteArrayToStringSid(ByRef bArray As Byte()) As String

.

   Dim ptrSID As IntPtr = Nothing

.

     Dim sSID As String = String.Empty

.

     If ConvertSidToStringSid(bArray, ptrSID) = True Then

.

       sSID = System.Runtime.InteropServices.Marshal.PtrToStringAuto(ptrSID)

.

     Return sSID

.

     System.Runtime.InteropServices.Marshal.FreeHGlobal(ptrSID)

.

private string ConvertByteToStringSid(Byte[] sidBytes)

.

        StringBuilder strSid = new StringBuilder();

.

        strSid.Append("S-");

.

        // Add SID revision.

.

        strSid.Append(sidBytes[0].ToString());

.

        sSubAuthorityCount = Convert.ToInt16(sidBytes[1]);

.

        // Next six bytes are SID authority value.

.

        if (sidBytes[2] != 0 || sidBytes[3] != 0)

.

                           (Int16) sidBytes[2],

.

                           (Int16) sidBytes[3],

.

                           (Int16) sidBytes[4],

.

                           (Int16) sidBytes[5],

.

                           (Int16) sidBytes[6],

.

                           (Int16) sidBytes[7]);

.

            strSid.Append("-");

.

            strSid.Append(strAuth);

.

            Int64 iVal = sidBytes[7] +

.

                 (sidBytes[6] << 8) +

.

                 (sidBytes[5] << 16) +

.

                 (sidBytes[4] << 24);

.

            strSid.Append("-");

.

            strSid.Append(iVal.ToString());

.

            UInt32 iSubAuth = BitConverter.ToUInt32(sidBytes, idxAuth);

.

            strSid.Append("-");

.

            strSid.Append(iSubAuth.ToString());

.

        return strSid.ToString();

.

private string ConvertSidBytesToString(byte[] sidBytes)

.

   SecurityIdentifier si = new SecurityIdentifier(sidBytes, 0);

.

     $strSID='S-1-5-21-XXXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-1026'

.

     $binarySid = New-Object byte[] $sid.BinaryLength

.

     ([System.Security.Principal.SecurityIdentifier]$strSid).GetBinaryForm($binarySid,0)

.
Documentation
[ConvertSidToStringSid] on MSDN
. .
Summary
The ConvertStringSidToSid function converts a string-format SID into a valid, functional SID. You can use this function to retrieve a SID that the ConvertSidToStringSid function converted to string format.
.

static extern bool ConvertStringSidToSid(

.

            string StringSid,

.

            out IntPtr ptrSid

.

    Private Declare Auto Function ConvertSidToStringSid Lib "advapi32.dll" ( _

.

    ByVal Sid As IntPtr, _

.

    ByRef StringSid As IntPtr _

.

Dispose of the sid pointer using Marshal.FreeHGlobal() to avoid a memory leak

.

    static extern bool ConvertStringSidToSid(

.

        out IntPtr ptrSid);

.

    [DllImport("advapi32.dll", EntryPoint = "GetLengthSid", CharSet = CharSet.Auto)]

.

    static extern int GetLengthSid(IntPtr pSID);

.

        byte[] SID = null;

.

                IntPtr SID_ptr=new IntPtr(0);

.

                ConvertStringSidToSid(UserObject["SID"].ToString(), out SID_ptr);

.

                int size = (int)GetLengthSid(SID_ptr);

.

                SID = new byte[size];

.

                Marshal.Copy(SID_ptr, SID, 0, size);

.

                Marshal.FreeHGlobal(SID_ptr);

.

        Trustee["SID"] = SID;

.
Documentation
[ConvertStringSidToSid] on MSDN
.
Summary
Copies a security identifier (SID) to a buffer.
.

static extern bool CopySid(uint nDestinationSidLength, IntPtr pDestinationSid,

.

   IntPtr pSourceSid);

.

static extern bool CopySid(uint nDestinationSidLength, byte[] pDestinationSid,

.

   IntPtr pSourceSid);

.

Declare Function CopySid Lib "advapi32.dll" (ByVal nDestinationSidLength As Integer, _

.

   ByVal pDestinationSid As IntPtr, ByVal pSourceSid As IntPtr) As Boolean

.

    private static byte[] DuplicateSid(IntPtr pSid)

.

        uint length = UnsafeNativeMethods.GetLengthSid(pSid);

.

        UnsafeNativeMethods.CopySid(length, bytes, pSid);

.
Documentation
[CopySid] on MSDN
.

    Public processId As Integer

.

            public int    processId;

.
Summary
Creates a SID for predefined aliases
.

static extern bool CreateWellKnownSid(

.

    WELL_KNOWN_SID_TYPE WellKnownSidType,

.

    IntPtr DomainSid,

.

    IntPtr pSid,

.

    ref uint cbSid);

.

    Private Declare Function CreateWellKnownSid Lib "advapi32.dll" ( _

.

    ByVal WellKnownSidType As Integer, _

.

    ByVal DomainSid As IntPtr, _

.

    ByVal pSID As IntPtr, _

.

    ByRef cbSid As Integer _

.

WELL_KNOWN_SID_TYPE

.

  string GetWellKnownSID(WELL_KNOWN_SID_TYPE wellKnownSidType)

.

      IntPtr domainSid = IntPtr.Zero;

.

      IntPtr pSid = IntPtr.Zero;

.

      uint cbSid = 0;

.

      string sidString = string.Empty;

.

      NativeMethods.CreateWellKnownSid(wellKnownSidType, domainSid, pSid, ref cbSid);

.

      pSid = Marshal.AllocCoTaskMem(Convert.ToInt32(cbSid));

.

      if (NativeMethods.CreateWellKnownSid(wellKnownSidType, domainSid, pSid, ref cbSid))

.

      NativeMethods.ConvertSidToStringSid(pSid, out sidString);

.

      Marshal.FreeCoTaskMem(pSid);

.

      return sidString;

.

    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

.

var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null).ToString();

.
Documentation
.

    public enum CryptAlgSID : uint

.

    ALG_SID_ANY = (0),

.

    ALG_SID_RSA_ANY = 0,

.

    ALG_SID_RSA_PKCS = 1,

.

    ALG_SID_RSA_MSATWORK = 2,

.

    ALG_SID_RSA_ENTRUST = 3,

.

    ALG_SID_RSA_PGP = 4,

.

    ALG_SID_DSS_ANY = 0,

.

    ALG_SID_DSS_PKCS = 1,

.

    ALG_SID_DSS_DMS = 2,

.

    ALG_SID_ECDSA = 3,

.

    ALG_SID_DES = 1,

.

    ALG_SID_3DES = 3,

.

    ALG_SID_DESX = 4,

.

    ALG_SID_IDEA = 5,

.

    ALG_SID_CAST = 6,

.

    ALG_SID_SAFERSK64 = 7,

.

    ALG_SID_SAFERSK128 = 8,

.

    ALG_SID_3DES_112 = 9,

.

    ALG_SID_CYLINK_MEK = 12,

.

    ALG_SID_RC5 = 13,

.

    ALG_SID_AES_128 = 14,

.

    ALG_SID_AES_192 = 15,

.

    ALG_SID_AES_256 = 16,

.

    ALG_SID_AES = 17,

.

    ALG_SID_SKIPJACK = 10,

.

    ALG_SID_TEK = 11,

.

    ALG_SID_RC2 = 2,

.

    ALG_SID_RC4 = 1,

.

    ALG_SID_SEAL = 2,

.

    ALG_SID_DH_SANDF = 1,

.

    ALG_SID_DH_EPHEM = 2,

.

    ALG_SID_AGREED_KEY_ANY = 3,

.

    ALG_SID_KEA = 4,

.

    ALG_SID_ECDH = 5,

.

    ALG_SID_MD2 = 1,

.

    ALG_SID_MD4 = 2,

.

    ALG_SID_MD5 = 3,

.

    ALG_SID_SHA = 4,

.

    ALG_SID_SHA1 = 4,

.

    ALG_SID_MAC = 5,

.

    ALG_SID_RIPEMD = 6,

.

    ALG_SID_RIPEMD160 = 7,

.

    ALG_SID_SSL3SHAMD5 = 8,

.

    ALG_SID_HMAC = 9,

.

    ALG_SID_TLS1PRF = 10,

.

    ALG_SID_HASH_REPLACE_OWF = 11,

.

    ALG_SID_SHA_256 = 12,

.

    ALG_SID_SHA_384 = 13,

.

    ALG_SID_SHA_512 = 14,

.

    ALG_SID_SSL3_MASTER = 1,

.

    ALG_SID_SCHANNEL_MASTER_HASH = 2,

.

    ALG_SID_SCHANNEL_MAC_KEY = 3,

.

    ALG_SID_PCT1_MASTER = 4,

.

    ALG_SID_SSL2_MASTER = 5,

.

    ALG_SID_TLS1_MASTER = 6,

.

    ALG_SID_SCHANNEL_ENC_KEY = 7,

.

    ALG_SID_ECMQV = 1

.

    CALG_MD2 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_MD2),

.

    CALG_MD4 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_MD4),

.

    CALG_MD5 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_MD5),

.

    CALG_SHA = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_SHA),

.

    CALG_SHA1 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_SHA1),

.

    CALG_MAC = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_MAC),

.

    CALG_RSA_SIGN = (CryptAlgClass.ALG_CLASS_SIGNATURE | CryptAlgType.ALG_TYPE_RSA | CryptAlgSID.ALG_SID_RSA_ANY),

.

    CALG_DSS_SIGN = (CryptAlgClass.ALG_CLASS_SIGNATURE | CryptAlgType.ALG_TYPE_DSS | CryptAlgSID.ALG_SID_DSS_ANY),

.

    CALG_NO_SIGN = (CryptAlgClass.ALG_CLASS_SIGNATURE | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_ANY),

.

    CALG_RSA_KEYX = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_RSA | CryptAlgSID.ALG_SID_RSA_ANY),

.

    CALG_DES = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_DES),

.

    CALG_3DES_112 = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_3DES_112),

.

    CALG_3DES = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_3DES),

.

    CALG_DESX = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_DESX),

.

    CALG_RC2 = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_RC2),

.

    CALG_RC4 = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_STREAM | CryptAlgSID.ALG_SID_RC4),

.

    CALG_SEAL = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_STREAM | CryptAlgSID.ALG_SID_SEAL),

.

    CALG_DH_SF = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_DH | CryptAlgSID.ALG_SID_DH_SANDF),

.

    CALG_DH_EPHEM = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_DH | CryptAlgSID.ALG_SID_DH_EPHEM),

.

    CALG_AGREEDKEY_ANY = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_DH | CryptAlgSID.ALG_SID_AGREED_KEY_ANY),

.

    CALG_KEA_KEYX = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_DH | CryptAlgSID.ALG_SID_KEA),

.

    CALG_HUGHES_MD5 = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_MD5),

.

    CALG_SKIPJACK = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_SKIPJACK),

.

    CALG_TEK = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_TEK),

.

    CALG_CYLINK_MEK = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_CYLINK_MEK),

.

    CALG_SSL3_SHAMD5 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_SSL3SHAMD5),

.

    CALG_SSL3_MASTER = (CryptAlgClass.ALG_CLASS_MSG_ENCRYPT | CryptAlgType.ALG_TYPE_SECURECHANNEL | CryptAlgSID.ALG_SID_SSL3_MASTER),

.

    CALG_SCHANNEL_MASTER_HASH = (CryptAlgClass.ALG_CLASS_MSG_ENCRYPT | CryptAlgType.ALG_TYPE_SECURECHANNEL | CryptAlgSID.ALG_SID_SCHANNEL_MASTER_HASH),

.

    CALG_SCHANNEL_MAC_KEY = (CryptAlgClass.ALG_CLASS_MSG_ENCRYPT | CryptAlgType.ALG_TYPE_SECURECHANNEL | CryptAlgSID.ALG_SID_SCHANNEL_MAC_KEY),

.

    CALG_SCHANNEL_ENC_KEY = (CryptAlgClass.ALG_CLASS_MSG_ENCRYPT | CryptAlgType.ALG_TYPE_SECURECHANNEL | CryptAlgSID.ALG_SID_SCHANNEL_ENC_KEY),

.

    CALG_PCT1_MASTER = (CryptAlgClass.ALG_CLASS_MSG_ENCRYPT | CryptAlgType.ALG_TYPE_SECURECHANNEL | CryptAlgSID.ALG_SID_PCT1_MASTER),

.

    CALG_SSL2_MASTER = (CryptAlgClass.ALG_CLASS_MSG_ENCRYPT | CryptAlgType.ALG_TYPE_SECURECHANNEL | CryptAlgSID.ALG_SID_SSL2_MASTER),

.

    CALG_TLS1_MASTER = (CryptAlgClass.ALG_CLASS_MSG_ENCRYPT | CryptAlgType.ALG_TYPE_SECURECHANNEL | CryptAlgSID.ALG_SID_TLS1_MASTER),

.

    CALG_RC5 = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_RC5),

.

    CALG_HMAC = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_HMAC),

.

    CALG_TLS1PRF = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_TLS1PRF),

.

    CALG_HASH_REPLACE_OWF = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_HASH_REPLACE_OWF),

.

    CALG_AES_128 = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_AES_128),

.

    CALG_AES_192 = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_AES_192),

.

    CALG_AES_256 = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_AES_256),

.

    CALG_AES = (CryptAlgClass.ALG_CLASS_DATA_ENCRYPT | CryptAlgType.ALG_TYPE_BLOCK | CryptAlgSID.ALG_SID_AES),

.

    CALG_SHA_256 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_SHA_256),

.

    CALG_SHA_384 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_SHA_384),

.

    CALG_SHA_512 = (CryptAlgClass.ALG_CLASS_HASH | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_SHA_512),

.

    CALG_ECDH = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_DH | CryptAlgSID.ALG_SID_ECDH),

.

    CALG_ECMQV = (CryptAlgClass.ALG_CLASS_KEY_EXCHANGE | CryptAlgType.ALG_TYPE_ANY | CryptAlgSID.ALG_SID_ECMQV),

.

    CALG_ECDSA = (CryptAlgClass.ALG_CLASS_SIGNATURE | CryptAlgType.ALG_TYPE_DSS | CryptAlgSID.ALG_SID_ECDSA)

.

     public int processId;

.
Summary
Tests two SID values for equality
.

static extern bool EqualSid(IntPtr pSid1, IntPtr pSid2);

.

    Private Declare Function EqualSid Lib "advapi32.dll" ( _

.

    ByVal pSid1 As IntPtr, _

.

    ByVal pSid2 As IntPtr _

.
Documentation
.
Summary
.

static extern IntPtr FreeSid(IntPtr pSid);

.

Declare Function FreeSid Lib "advapi32.dll" (ByVal pSid As IntPtr) As IntPtr

.
Documentation
[FreeSid] on MSDN
46: GetAce
.

    static extern int GetLengthSid(

.

        IntPtr pSID

.

    static extern bool ConvertSidToStringSid(

.

        [MarshalAs(UnmanagedType.LPArray)] byte[] pSID,

.

        out IntPtr ptrSid

.

        public int SidStart;

.

                    IntPtr iter = (IntPtr)((long)pAce + (long)Marshal.OffsetOf(typeof(ACCESS_ALLOWED_ACE), "SidStart"));

.

                    byte[] bSID = null;

.

                    int size = (int)GetLengthSid(iter);

.

                    bSID = new byte[size];

.

                    Marshal.Copy(iter, bSID, 0, size);

.

                    IntPtr ptrSid;

.

                    ConvertSidToStringSid(bSID, out ptrSid);

.

                    string strSID = Marshal.PtrToStringAuto(ptrSid);

.

                    Console.WriteLine("{0} : {1}/{2}/{3}", strSID, ace.Header.AceType.ToString(), ace.Mask.ToString(), ace.Header.AceFlags.ToString());

.

    Dim SidString, NameBuf As String

.
Summary
Returns the length in bytes of a valid SID
.

static extern uint GetLengthSid(IntPtr pSid);

.

    Public Declare Function GetLengthSid Lib "advapi32.dll"( _

.

        pSID As System.IntPtr _

.

If pSid points to an unamanged array of bytes containing a SID, this function determines the length of the SID (by the formula: 8 + 4 times the value of the second byte), which you need to know, for example, when copying the SID into a managed byte array.

.

Consider also the use of CopySid instead of Marshal.Copy below. MSDN isn't clear if that is necessary or not, but better safe than sorry.

.

public static byte[] GetSidFromString(string stringSid)

.

    IntPtr pSid;

.

    if ( !ConvertStringSidToSid(stringSid, out pSid) )

.

        int length = (int) GetLengthSid(pSid);

.

        byte[] sid = new byte[length];

.

        Marshal.Copy(pSid, sid, 0, length);

.

        return sid;

.

        LocalFree(pSid);

.
Documentation
[GetLengthSid] on MSDN
.

    out IntPtr pSidOwner,

.

    out IntPtr pSidGroup,

.

    ByRef pSidOwner As IntPtr, _

.

    ByRef pSidGroup As IntPtr, _

.

Also, the example given below is mildly incompatible with the example given for LookupAccountSid() on this site.

.

    IntPtr pSid = pZero;

.

        out pSid, out pZero, out pZero, out pZero, out psd);

.

    int _sidNameUse= 0;

.

    errorReturn = LookupAccountSid(null, pSid, _account, ref _accounLength, _domain, ref _domainLength, out _sidNameUse);

.

        Console.WriteLine("LookupAccountSid: {0}", Marshal.GetLastWin32Error());

.

out IntPtr pSidOwner,

.

out IntPtr  pSidGroup,

.

        ByRef pSidOwner As IntPtr, _

.

        ByRef pSidGroup As IntPtr, _

.

        out IntPtr          sidOwner,

.

        out IntPtr          sidGroup,

.

    static extern bool ConvertSidToStringSid(

.

        IntPtr              sid,

.

        out IntPtr          sidString);      

.

        IntPtr ownerSid;

.

        IntPtr groupSid;

.

        returnValue = GetSecurityInfo(fileStream.Handle, SE_OBJECT_TYPE.SE_FILE_OBJECT, SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION | SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, out ownerSid, out groupSid, out dacl, out sacl, out securityDescriptor);          

.

        IntPtr sidString = IntPtr.Zero;

.

        success = ConvertSidToStringSid(ownerSid, out sidString);

.

        Console.WriteLine(Marshal.PtrToStringAuto(sidString));

.

        Marshal.FreeHGlobal(sidString);

.
Summary
The GetSidIdentifierAuthority function returns a pointer to the SID_IDENTIFIER_AUTHORITY structure in a specified security identifier (SID).
.

static extern TODO GetSidIdentifierAuthority(TODO);

.

Declare Function GetSidIdentifierAuthority Lib "advapi32.dll" (

.

   ByVal psid As IntPtr

.

'Extract the authority record from the SID.

.

Runtime.InteropServices.Marshal.Copy(GetSidIdentifierAuthority(pSID), sia, 0, 6)

.
Documentation
[GetSidIdentifierAuthority] on MSDN
.
Summary
The GetSidLengthRequired function returns the length, in bytes, of the buffer required to store a SID with a specified number of subauthorities.
.

static extern TODO GetSidLengthRequired(TODO);

.

Declare Function GetSidLengthRequired Lib "advapi32.dll" (ByVal nSubAuthorityCount As Byte) As Integer

.

Dim pSID As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(GetSidLengthRequired(iSubAuthorityCount))

.
Documentation
[GetSidLengthRequired] on MSDN
.
Summary
The GetSidSubAuthorityCount function returns a pointer to the member in a security identifier (SID) structure containing the subauthority count
.

static extern IntPtr GetSidSubAuthorityCount(IntPtr psid);

.

Declare Function GetSidSubAuthorityCount Lib "advapi32.dll" (

.

   ByVal psid As IntPtr

.

Dim numSubAuthorities As Byte = Runtime.InteropServices.Marshal.ReadByte(GetSidSubAuthorityCount(pSID), 0)

.

' a WinNT version of the ConvertSidToStringSid function

.

Private Shared Function ConvertSidToStringSidNT(ByVal Sid As IntPtr) As String

.

   Dim psia As SID_IDENTIFIER_AUTHORITY

.

   If Not IsValidSid(Sid) Then

.

   iptr = GetSidIdentifierAuthority(Sid)

.

   psia = CType(Marshal.PtrToStructure(iptr, GetType(SID_IDENTIFIER_AUTHORITY)), SID_IDENTIFIER_AUTHORITY)

.

   iptr = GetSidSubAuthorityCount(Sid)

.

     iptr = GetSidSubAuthority(Sid, i)

.
Documentation
[GetSidSubAuthorityCount] on MSDN
.
Summary
The GetSidSubAuthorityCount function returns a pointer to the member in a security identifier (SID) structure containing the subauthority count
.

static extern TODO GetSidSubAuthorityCount(TODO);

.

Declare Function GetSidSubAuthorityCount Lib "advapi32.dll" (

.

   ByVal psid As IntPtr

.

Dim numSubAuthorities As Byte = Runtime.InteropServices.Marshal.ReadByte(GetSidSubAuthorityCount(pSID), 0)

.

' a WinNT version of the ConvertSidToStringSid function

.

Private Shared Function ConvertSidToStringSidNT(ByVal Sid As IntPtr) As String

.

   Dim psia As SID_IDENTIFIER_AUTHORITY

.

   If Not IsValidSid(Sid) Then

.

   iptr = GetSidIdentifierAuthority(Sid)

.

   psia = CType(Marshal.PtrToStructure(iptr, GetType(SID_IDENTIFIER_AUTHORITY)), SID_IDENTIFIER_AUTHORITY)

.

   iptr = GetSidSubAuthorityCount(Sid)

.

     iptr = GetSidSubAuthority(Sid, i)

.
Documentation
[GetSidSubAuthorityCount] on MSDN
.

// Prints out sid of current user

.

            TokenRestrictedSids,

.

            public SID_AND_ATTRIBUTES User ;

.

        public struct SID_AND_ATTRIBUTES

.

            public IntPtr Sid ;

.

        // Using IntPtr for pSID insted of Byte[]

.

        static extern bool ConvertSidToStringSid(

.

            IntPtr pSID,

.

            out IntPtr ptrSid);

.

            Result = GetTokenInformation( WindowsIdentity.GetCurrent().Token , TOKEN_INFORMATION_CLASS.TokenUser , IntPtr.Zero , TokenInfLength , out TokenInfLength );

.

            Result = GetTokenInformation( WindowsIdentity.GetCurrent().Token  , TOKEN_INFORMATION_CLASS.TokenUser , TokenInformation , TokenInfLength , out TokenInfLength ) ;

.

                Boolean ok = ConvertSidToStringSid( TokenUser.User.Sid  , out pstr );

.

                string sidstr = Marshal.PtrToStringAuto( pstr );

.

                Console.WriteLine(@"Found sid {0}",sidstr);

.

There's a sample based on this at http://stackoverflow.com/questions/2146153/how-to-get-the-logon-sid-in-c/2146418#2146418 that gets the LogonSID instead.

. .

[WindowsIdentity.Impersonate]

.
Summary
The InitializeSid function initializes a security identifier (SID).
.

        internal unsafe static extern BOOL InitializeSid(

.

        IntPtr Sid,

.

        SID_IDENTIFIER_AUTHORITY* pIdentifierAuthority,

.

        Declare Function InitializeSid Lib "advapi32.dll" (ByVal psid As IntPtr, ByRef pIdentifierAuthority As SID_IDENTIFIER_AUTHORITY, ByVal nSubAuthorityCount As Byte) As Integer

.

SID_IDENTIFIER_AUTHORITY

.

  Dim sia As SID_IDENTIFIER_AUTHORITY

.

  'Allocate a SID large enough for the number of sub-authorities present.

.

  Dim pSID As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(GetSidLengthRequired(sidParts.Length - 1))

.

  'Initialise the SID.

.

  If InitializeSid(pSID, sia, sidParts.Length - 1) = 0 Then

.

    Throw New Exception("Unexpected error trying to initialise a SID.")

.
Documentation
[InitializeSid] on MSDN
.

private static extern bool IsValidSid([MarshalAs(UnmanagedType.LPArray)] byte[] pSid);

.

Declare Function IsValidSid  Lib "advapi32.dll" (TODO) As TODO

.
Documentation
IsValidSid @msdn on MSDN
.

static extern bool IsValidSid([MarshalAs(UnmanagedType.LPArray)] byte[] pSid);

.

Declare Function IsValidSid Lib "advapi32.dll" (TODO) As TODO

.

    enum SID_NAME_USE {

.

        SidTypeUser = 1,

.

        SidTypeGroup,

.

        SidTypeDomain,

.

        SidTypeAlias,

.

        SidTypeWellKnownGroup,

.

        SidTypeDeletedAccount,

.

        SidTypeInvalid,

.

        SidTypeUnknown,

.

        SidTypeComputer

.

        [MarshalAs(UnmanagedType.LPArray)] byte[] Sid,

.

        ref uint cbSid,

.

        out SID_NAME_USE peUse);

.

    static extern bool ConvertSidToStringSid(

.

        [MarshalAs(UnmanagedType.LPArray)] byte[] pSID,

.

        out IntPtr ptrSid);

.

    static extern bool IsValidSid([MarshalAs(UnmanagedType.LPArray)] byte[] pSid);

.

        byte [] Sid = null;

.

        uint cbSid = 0;

.

        SID_NAME_USE sidUse;

.

        if (!LookupAccountName(null,accountName,Sid,ref cbSid,referencedDomainName,ref cchReferencedDomainName,out sidUse))

.

            Sid = new byte[cbSid];

.

            if (!LookupAccountName(null,accountName,Sid,ref cbSid,referencedDomainName,ref cchReferencedDomainName,out sidUse))

.

        // Consider throwing an exception since no result was found

.

        if (IsValidSid(Sid)) {

.

            Console.WriteLine("SID is a valid SID..");

.

            Console.WriteLine("SID  is an unvalid SID..");

.

        IntPtr ptrSid;

.

        if (!ConvertSidToStringSid(Sid,out ptrSid))

.

            Console.WriteLine(@"Could not convert sid to string. Error : {0}",err);

.

            string sidString = Marshal.PtrToStringAuto(ptrSid);

.

            LocalFree(ptrSid);

.

            Console.WriteLine(@"Found sid {0} : {1}",sidUse,sidString);

.
Documentation
[IsValidSid] on MSDN
.

  IntPtr ppLogonSid, // nullable

.

  ByVal ppLogonSid As IntPtr, _

Cut off search results after 60. Please refine your search.


 
Access PInvoke.net directly from VS: