WindowsIdentity.GetCurrent 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回表示当前 Windows 用户的 WindowsIdentity 对象。
重载
GetCurrent(TokenAccessLevels) |
返回一个 WindowsIdentity 对象,该对象使用指定的所需标记访问级别来表示当前 Windows 用户。 |
GetCurrent(Boolean) |
返回一个 WindowsIdentity 对象,该对象表示线程或进程(具体取决于 |
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 用户的对象。
注解
如果 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 如何使用方法返回 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