远程机器上卸下的用户帐户我的代码:从管理员组使用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