Share via


WindowsIdentity.GetCurrent 方法

定义

返回表示当前 Windows 用户的 WindowsIdentity 对象。

重载

GetCurrent(TokenAccessLevels)

返回一个 WindowsIdentity 对象,该对象使用指定的所需标记访问级别来表示当前 Windows 用户。

GetCurrent(Boolean)

返回一个 WindowsIdentity 对象,该对象表示线程或进程(具体取决于 ifImpersonating 参数的值)的 Windows 标识。

GetCurrent()

返回表示当前 Windows 用户的 WindowsIdentity 对象。

GetCurrent(TokenAccessLevels)

返回一个 WindowsIdentity 对象,该对象使用指定的所需标记访问级别来表示当前 Windows 用户。

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

参数

desiredAccess
TokenAccessLevels

枚举值的按位组合。

返回

表示当前用户的对象。

注解

参数 desiredAccess 指定一个访问掩码,该掩码标识访问令牌的请求访问类型。 这些请求的访问类型与令牌的任意访问控制列表 (DACL) 进行比较,以确定授予或拒绝了哪些访问类型。

适用于

GetCurrent(Boolean)

返回一个 WindowsIdentity 对象,该对象表示线程或进程(具体取决于 ifImpersonating 参数的值)的 Windows 标识。

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

参数

ifImpersonating
Boolean

如果为 true,则仅在线程当前正在模拟时才返回 WindowsIdentity;如果为 false,则在线程正在模拟时返回线程的 WindowsIdentity,或在线程当前没有模拟时返回进程的 WindowsIdentity

返回

表示 Windows 用户的对象。

注解

如果 ifImpersonatingtrue 且线程未模拟,则返回 WindowsIdentity 的对象没有值。 如果 ifImpersonatingfalse 并且线程正在模拟, WindowsIdentity 则返回线程的 。 如果 ifImpersonatingfalse 且线程未模拟, WindowsIdentity 则返回进程的 。

适用于

GetCurrent()

返回表示当前 Windows 用户的 WindowsIdentity 对象。

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

返回

表示当前用户的对象。

例外

调用方没有正确的权限。

示例

以下代码演示如何使用 GetCurrent 方法返回 WindowsIdentity 表示当前 Windows 用户的 对象。 此代码示例是为 WindowsIdentity 类提供的一个更大示例的一部分。

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

适用于