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

列舉值的位元組合。

傳回

WindowsIdentity

物件,表示目前的使用者。

備註

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

傳回

WindowsIdentity

物件,表示 Windows 使用者。

備註

如果 ifImpersonating 為, true 且執行緒不是模擬,則傳回的 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

傳回

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

適用於