Declare Auto Function LsaLookupSids Lib "advapi32.dll" (PolicyHandle As IntPtr, Count As Integer, ByRef Sids As IntPtr, ByRef ReferencedDomains As IntPtr, ByRef Names As IntPtr) As Integer
User-Defined Types:
<StructLayout(LayoutKind.Sequential)> Structure LSA_REFERENCED_DOMAIN_LIST Public Entries As ULong Public Domains As LSA_TRUST_INFORMATION End Structure<StructLayout(LayoutKind.Sequential)> Structure LSA_TRUST_INFORMATION Public Name As LSA_UNICODE_STRING Public Sid As IntPtr End Structure<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> Structure LSA_UNICODE_STRINGPublic Length, MaximumLength As UShort <MarshalAs(UnmanagedType.LPWStr)> Public Buffer As String End Structure<StructLayout(LayoutKind.Sequential)> Structure LSA_TRANSLATED_NAME Public Use As SID_NAME_USE, Name As LSA_UNICODE_STRING, DomainIndex As Long End Structure Enum SID_NAME_USE SidTypeUser =1 SidTypeGroup SidTypeDomain SidTypeAlia SidTypeWellKnownGroup SidTypeDeletedAccount SidTypeInvalid SidTypeUnknown SidTypeComputer SidTypeLabel End Enum
using System;
using System.Collections.Generic;
using System.Text;
namespace LsaSecurity
{
/*
* LsaWrapper class credit: Willy Denoyette [MVP]
*
* http://www.hightechtalks.com/csharp/lsa-functions-276626.html
*
* Added support for:
*
* LsaLookupSids
*
* for the purposes of providing a working example.
*
*
*
*/
using System.Runtime.InteropServices;
using System.Security;
using System.Management;
using System.Runtime.CompilerServices;
using System.ComponentModel;
using LSA_HANDLE = IntPtr;
public class Program
{
public static void Main()
{
using (LsaWrapper lsaSec = new LsaWrapper())
{
string[] accounts = lsaSec.GetUsersWithPrivilege("SeNetworkLogonRight");
}
}
}