我們有一個過程,需要檢查特定用戶是否是本地管理員組的成員。如何在檢查用戶是否是組的成員時克服「成員的SID無法解決」錯誤?
,檢查看起來像以下代碼:
using (PrincipalContext context = new PrincipalContext(ContextType.Machine, null))
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, sUserName);
if (user != null)
{
SecurityIdentifier adminsGroupSID = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
GroupPrincipal group = GroupPrincipal.FindByIdentity(context, IdentityType.Sid, adminsGroupSID.Value);
if (group != null)
{
if (user.IsMemberOf(group))
return 0;
}
}
}
當擁有賬戶(如域帳戶),其被拆除,我們得到一個PrincipalOperationException和消息「錯誤(1332)在枚舉組成員身份時發生,成員的SID無法解析。「
有沒有什麼辦法可以解決這個問題: a)手動刪除組中的孤兒SID b)不忽略它?
感謝
謝謝你的答覆。我會檢查可以做些什麼。另外,可能你會推薦一些類似的解決方案來將用戶添加到組中?當我們做group.Members.Add(用戶)時,會出現同樣的問題。 –
那麼,底層對象將始終有效,但並不像AccountManagement-Namespace那麼舒服。但似乎AccountManagement-Namespace有一些缺陷,需要解決方法。你也可以編寫修復功能...... – TGlatzer
@TGlatzer:我如何枚舉?循環播放時出現錯誤。 HTTP://計算器。com/questions/35913995/while-trying-to-resolve-a-cross-store-reference-the-sid-of-the-target-principal –