Share via


WindowsIdentity.GetCurrent 方法

定義

傳回表示目前 Windows 使用者的 WindowsIdentity 物件。

多載

GetCurrent(TokenAccessLevels)

使用指定所要的語彙基元存取層級,傳回代表目前 Windows 使用者的 WindowsIdentity 物件。

GetCurrent(Boolean)

傳回表示執行緒或處理程序之 Windows 識別的 WindowsIdentity 物件,視 ifImpersonating 參數的值而定。

GetCurrent()

傳回表示目前 Windows 使用者的 WindowsIdentity 物件。

GetCurrent(TokenAccessLevels)

使用指定所要的語彙基元存取層級,傳回代表目前 Windows 使用者的 WindowsIdentity 物件。

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)

傳回表示執行緒或處理程序之 Windows 識別的 WindowsIdentity 物件,視 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 表示只有當執行緒目前正在模擬時才會傳回 WindowsIdentityfalse 則表示如果執行緒目前正在模擬時,會傳回執行緒的 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

適用於