惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
有赞技术团队
有赞技术团队
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
博客园 - 【当耐特】
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
The Cloudflare Blog
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
Vercel News
Vercel News
IT之家
IT之家
MyScale Blog
MyScale Blog
博客园_首页
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
罗磊的独立博客

博客园 - Samgle

HttpRequest重写,解决资源占用/链接超时/分块下载事件通知 问题。 PDF-XChange 3.0 / Pro4.0注册码 Welcome to the Live Labs Pivot Technical Preview 修复 VS2008 asp.net 设计视图 失效/工具-选项[Html设计视图]出现"加载此属性页时出错" 方案 对于JavaScript的 Stack overflow at line 错误总结 - Samgle 10 Free Chart Scripts 如何让mvc运行在IIS6.0上? (ASP.NET MVC on IIS 6 Walkthrough) Live.com MSN 在线状态查询接口(JSON数据输出) - Samgle BIND9.5b1 for windows 2003 Google Maps by asp.net API集成-S.Sams Olympic Medal 如何在asp.net中用jQuery实现便捷的提示功能和表单验证功能-S.Sams jQuery jGrow 改进版 通过代理访问 http://sourceforge.net/ 常用简易JavaScript函数 世界真細小 (原曲: It's A Small World), 作曲: Richard She 做下笔记, Response 文件流类型 推荐微软官方Windows Server 2008实战攻略系列下载 Most used CSS tricks
解决删除域用户Exception from HRESULT: 0x80072030
Samgle · 2013-11-27 · via 博客园 - Samgle

解决删除域用户异常问题。


System.DirectoryServices.DirectoryServicesCOMException was unhandled
  Message=在服务器上没有这样一个对象。 (Exception from HRESULT: 0x80072030)
  Source=System.DirectoryServices
  ErrorCode=-2147016656
  ExtendedError=8333
  ExtendedErrorMessage=0000208D: NameErr: DSID-031001CD, problem 2001 (NO_OBJECT), data 0, best match of:
    'CN=Users,DC=samshum,DC=com'

解决方案代码:

        private const string AdPath= "LDAP://192.168.8.151";
        private const string AdUser= "administrator";
        private const string AdPassWord= "1231112123";

        /// <summary>
        /// 删除指定用户
        /// </summary>
        /// <param name="sAMAccountName"></param>
        public void DeleteUserByAccount(string sAMAccountName)
        {
            GetCommonName(sAMAccountName);
        }

        /// <summary>
        /// 删除指定用户,通过用户全称
        /// </summary>
        /// <param name="NickName"></param>
        public void DeleteUserByNickName(string NickName)
        {
            using (DirectoryEntry entry = new DirectoryEntry(ADPath, ADUser, ADPassword))
            {
                using (DirectorySearcher Search = new DirectorySearcher())
                {
                    Search.SearchRoot = entry;
                    Search.Filter = "(&(objectClass=user) (cn=" + NickName + "))";
                    SearchResult Result = Search.FindOne();
                    using (DirectoryEntry child = Result.GetDirectoryEntry())
                    {
                        child.DeleteTree();
                        child.Close();
                        child.Dispose();
                    }
                    Search.Dispose();
                }
                entry.Close();
                entry.Dispose();
            }
        }