WindowsIdentity.GetCurrent 方法

定义

返回一个代表当前Windows用户的 WindowsIdentity 对象。

重载

名称 说明
GetCurrent(TokenAccessLevels)

返回一个 WindowsIdentity 对象,该对象代表当前Windows用户使用指定的所需令牌访问级别。

GetCurrent(Boolean)

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

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 对象,该对象代表线程或进程的Windows标识,具体取决于 ifImpersonating 参数的值。

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用户的对象。

注解

ifImpersonating如果是true且线程未模拟,则WindowsIdentity返回的对象没有值。 ifImpersonating如果是false且线程正在模拟,WindowsIdentity则返回该线程。 ifImpersonating如果是false且线程未模拟,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 方法返回表示当前Windows用户的 WindowsIdentity 对象。 该代码示例是 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

适用于