This documentation is archived and is not being maintained.

WindowsIdentity::Token Property

Updated: January 2010

Gets the Windows account token for the user.

Namespace:  System.Security.Principal
Assembly:  mscorlib (in mscorlib.dll)

public:
virtual property IntPtr Token {
	IntPtr get ();
}

Property Value

Type: System::IntPtr
The handle of the access token associated with the current execution thread.

Do not explicitly release the account token that is returned by the Token property. The token is released by the Dispose method, which you can call in code. Dispose is also automatically called by the garbage collector.

NoteNote:

The account token that is returned by the Token property is a duplicate of the Windows token that is used to create the WindowsIdentity object and is automatically released by the .NET Framework. This is different from the account token (the userToken parameter for the constructor), which is used to create the WindowsIdentity object. userToken is a Windows account token that is created by a call to LogonUser and must be closed to avoid a memory leak.

The following code shows the use of the IsSystem property to get the Windows account token for the user. This code example is part of a larger example provided for the WindowsIdentity class.

IntPtr accountToken = WindowsIdentity::GetCurrent()->Token;

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Date

History

Reason

January 2010

Added note explaining why you do not need to release the account token.

Customer feedback.

Show: