Imports System
Imports System.Security.Principal
Class WindowsIdentityMembers
Public Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Boolean
<STAThread()> _
Shared Sub Main(ByVal args() As String)
Dim accountToken As IntPtr
accountToken = WindowsIdentity.GetCurrent().Token
Dim windowsIdentity1 As New WindowsIdentity(accountToken)
Dim si As SecurityIdentifier = windowsIdentity1.Owner
Console.WriteLine(si.ToString())
si = windowsIdentity1.User
Console.WriteLine(si.ToString())
Dim irc As IdentityReferenceCollection = windowsIdentity1.Groups
Dim ir As IdentityReference
For Each ir In irc
Console.WriteLine(ir.Value)
Next ir
Dim token As TokenImpersonationLevel = windowsIdentity1.ImpersonationLevel
Console.WriteLine(token.ToString())
' Free the tokens.
If Not System.IntPtr.op_Equality(accountToken, IntPtr.Zero) Then
CloseHandle(accountToken)
End If
End Sub 'Main
End Class 'WindowsIdentityMembers