[DllImport("advapi32.dll", SetLastError=true)]
static extern TODO BuildTrusteeWithSid(TODO);
Private Declare Auto Sub BuildTrusteeWithSid Lib "advapi32.dll" ( _
ByVal pTrustee As IntPtr, _
ByVal pSid As IntPtr _
)
TRUSTEE
None.
Please add some!
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)
Do you know one? Please contribute it!