WindowsIdentity.GetCurrent Method

Definition

Returns a WindowsIdentity object that represents the current Windows user.

Overloads

GetCurrent(TokenAccessLevels)

Returns a WindowsIdentity object that represents the current Windows user, using the specified desired token access level.

GetCurrent(Boolean)

Returns a WindowsIdentity object that represents the Windows identity for either the thread or the process, depending on the value of the ifImpersonating parameter.

GetCurrent()

Returns a WindowsIdentity object that represents the current Windows user.

GetCurrent(TokenAccessLevels)

Returns a WindowsIdentity object that represents the current Windows user, using the specified desired token access level.

public:
 static System::Security::Principal::WindowsIdentity ^ GetCurrent(System::Security::Principal::TokenAccessLevels desiredAccess);
public static System.Security.Principal.WindowsIdentity GetCurrent (System.Security.Principal.TokenAccessLevels desiredAccess);
static member GetCurrent : System.Security.Principal.TokenAccessLevels -> System.Security.Principal.WindowsIdentity
Public Shared Function GetCurrent (desiredAccess As TokenAccessLevels) As WindowsIdentity

Parameters

desiredAccess
TokenAccessLevels

A bitwise combination of the enumeration values.

Returns

An object that represents the current user.

Remarks

The desiredAccess parameter specifies an access mask that identifies the requested types of access to the access token. These requested access types are compared with the token's discretionary access control list (DACL) to determine which types of access are granted or denied.

Applies to

GetCurrent(Boolean)

Returns a WindowsIdentity object that represents the Windows identity for either the thread or the process, depending on the value of the ifImpersonating parameter.

public:
 static System::Security::Principal::WindowsIdentity ^ GetCurrent(bool ifImpersonating);
public static System.Security.Principal.WindowsIdentity GetCurrent (bool ifImpersonating);
public static System.Security.Principal.WindowsIdentity? GetCurrent (bool ifImpersonating);
static member GetCurrent : bool -> System.Security.Principal.WindowsIdentity
Public Shared Function GetCurrent (ifImpersonating As Boolean) As WindowsIdentity

Parameters

ifImpersonating
Boolean

true to return the WindowsIdentity only if the thread is currently impersonating; false to return the WindowsIdentity of the thread if it is impersonating or the WindowsIdentity of the process if the thread is not currently impersonating.

Returns

An object that represents a Windows user.

Remarks

If ifImpersonating is true and the thread is not impersonating, the returned WindowsIdentity object has no value. If ifImpersonating is false and the thread is impersonating, the WindowsIdentity for the thread is returned. If ifImpersonating is false and the thread is not impersonating, the WindowsIdentity for the process is returned.

Applies to

GetCurrent()

Returns a WindowsIdentity object that represents the current Windows user.

public:
 static System::Security::Principal::WindowsIdentity ^ GetCurrent();
public static System.Security.Principal.WindowsIdentity GetCurrent ();
static member GetCurrent : unit -> System.Security.Principal.WindowsIdentity
Public Shared Function GetCurrent () As WindowsIdentity

Returns

An object that represents the current user.

Exceptions

The caller does not have the correct permissions.

Examples

The following code shows the use of the GetCurrent method to return a WindowsIdentity object that represents the current Windows user. This code example is part of a larger example provided for the WindowsIdentity class.

IntPtr accountToken = WindowsIdentity::GetCurrent()->Token;
IntPtr accountToken = WindowsIdentity.GetCurrent().Token;
Console.WriteLine( "Token number is: " + accountToken.ToString());
Dim accountToken As IntPtr = WindowsIdentity.GetCurrent().Token

Applies to