遠程機器上卸下的用戶帳戶我的代碼:從管理員組使用C#和AccountManagment命名空間
public bool RemoveUserFromAdministratorsGroup(UserPrincipal oUserPrincipal, string computer)
{
try
{
PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Machine, computer, null, ContextOptions.Negotiate, _sServiceUser, _sServicePassword);
GroupPrincipal oGroupPrincipal = GroupPrincipal.FindByIdentity(oPrincipalContext, "Administrators");
oGroupPrincipal.Members.Remove(oUserPrincipal);
oGroupPrincipal.Save();
return true;
}
catch
{
return false;
}
}
它沒有任何excaption工作。但是當我再次運行我的應用程序時,我在我的列表視圖中看到此用戶。所以,用戶沒有被刪除。
這也是我能枚舉一些本地或遠程機器級別組的唯一方法。當計算機級別組中存在域級別的主體時,AccountManagement名稱空間會有一些問題。例如,將CORP \ myuser添加到本地管理員組將導致GroupPrincipal上的成員屬性失敗。 – jproch