[英]Get real logged in user when impersonation is used
這是一個很難研究的問題...使用模擬時,我如何獲得登錄的“真實”用戶的名稱? 我知道有可能我先關閉模擬然后再重新打開,但這在我的情況下很困難,並且正在尋找更簡單的方法。
我嘗試了以下內容,所有這些都指向ImpersonationUser: Environment.UserName
WindowsIdentity.GetCurrent().Name
SystemInformation.Username
這是模擬用戶的代碼(不確定它的幫助程度):
if (LogonUser(userName, "ABDATA", pwd, LogonSessionType.Interactive, LogonProvider.Default, ref this._userToken))
{
if (DuplicateToken(this._userToken, SecurityImpersonationLevel.SecurityImpersonation, ref this._impersonationToken))
{
this._identity = new WindowsIdentity(this._impersonationToken, "Kerberos", WindowsAccountType.Normal, true);
this._impersonationContext = this._identity.Impersonate();
System.Threading.Thread.CurrentPrincipal = new WindowsPrincipal(this._identity);
}
else
{
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
}
我們基本上需要該模擬用戶的權限,以便它可以訪問某些文件,但希望出於責任制目的而能夠顯示實際登錄用戶的名稱。
真的在尋找任何解決方案..謝謝。
將用戶詳細信息緩存在ThreadStatic字段中 ?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.