使用 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;
}
}
它可以正常工作,没有任何解释。但是当我再次运行我的应用程序时,我在列表视图中看到该用户。因此,该用户没有被删除。
I have the code:
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;
}
}
It is worked without any excaption. But when i run my app again i see this user in my listview. So, the user wasn't removed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经解决了没有 AccountManagment 命名空间的问题。
I have solved the issue without AccountManagment namespace.
以下解决方案是在目录服务的帮助下删除用户...
The below solution is for deleting the user with the help of
Directory Service
...我不知道你的问题到底是什么,但以这种方式编码:
给我以下异常:
挖掘一些周围的信息,显示我正在不在目标域上的计算机上运行我的代码。当我从服务器本身运行相同的代码时,它可以工作。看来运行此代码的机器至少必须联系目标域的 DNS。
I don't know what is exactly your problem but coding this way :
Give me the following exception :
Digging a bit arround that show me that I was running my code on a computer that was not on the target domain. When I run the same code from the server itself it works. It seems that the machine running this code must at least contact the DNS of the target domain.