WindowsIdentity.Token Property

Definition

Gets the Windows account token for the user.

C#
public virtual IntPtr Token { get; }

Property Value

IntPtr

The handle of the access token associated with the current execution thread.

Examples

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.

C#
IntPtr accountToken = WindowsIdentity.GetCurrent().Token;
Console.WriteLine( "Token number is: " + accountToken.ToString());

Remarks

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.

Bilješka

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.

Applies to

Proizvod Verzije
.NET 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5