語言

WindowsIdentity.GetCurrent 方法

定義

回傳一個 WindowsIdentity 物件,代表目前的Windows使用者。

多載

名稱 Description
GetCurrent(TokenAccessLevels)

回傳一個 WindowsIdentity 物件,代表目前Windows使用者,使用指定的令牌存取層級。

GetCurrent(Boolean)

回傳一個 WindowsIdentity 物件,代表執行緒或程序的 Windows 身份,取決於 ifImpersonating 參數的值。

GetCurrent()

回傳一個 WindowsIdentity 物件,代表目前的Windows使用者。

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 ,則回傳 for the process。

適用於

GetCurrent()

回傳一個 WindowsIdentity 物件,代表目前的Windows使用者。

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

適用於