NTAccount user = (NTAccount)s.GetOwner(typeof(NTAccount));
Console.WriteLine(user);
}
...
printTheOwnerOfThisFile(@"c:\autoexec.bat");
在我的系統上運行這些代碼輸出了下面的字符串:
BUILTIN\Administrators
在稱為 WellKnownSidType 的新枚舉中還有一個人所共知的 SID 的完整列表。這使得不用對諸如“Administrators”(在德國它的拼寫與在美國的拼寫不同)之類的字符串進行硬編碼就可以構造人所共知帳戶的 SID。
WindowsIdentity 類也得到一些關注。如前所述,我最喜歡的一個新增功能就是重載 GetCurrent,這可使您在模擬過程中區分線程和進程安全性上下文:
bool ifImpersonating = true;
WindowsIdentity threadIdentity =
WindowsIdentity.GetCurrent(ifImpersonating);
if (null == threadIdentity) Console.WriteLine("Not impersonating");
else Console.WriteLine("Impersonating {0}",threadIdentity.Name);
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/