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

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - qjlyp

如何用Java 实现 Excel 表达式的解析(摘自:http://topic.csdn.net/t/20030408/17/1634982.html#) 群发UDP的性能测试 (摘自:http://www.cnblogs.com/trywebservice/archive/2008/02/19/1073642.html) 从底层了解ASP.NET体系结构 (http://www.cnblogs.com/rijing2004/archive/2007/09/14/howaspnetwork.html#8) C# 高级编程(第3版)--Active Directory编程(http://blog.chinaunix.net/u/884/showart_230743.html) LDAP应用程序接口(http://www.networkdictionary.cn/rfc/rfc1823.php#6) - qjlyp 定制你的LDAP目录的Schema(http://www.infoxa.com/asp/tech_file/xxnr_tech_201.htm) 浅析.Net下Active Directory(AD)编程技术(from :http://www.zysun.com/ldap/21944.html) 活动目录.NET编程Tips(摘:http://www.lupaworld.com/22221/viewspace_17754.html) 应用软件人才体系图 针对构架师的.NET 3.0 框架介绍( 摘自:http://www.chinaaspx.com/dotnet/aspnet/20070811/3489.html) Solving problems while passing XML into a Stored Procedure Rremoting 实现SQL Server 2005快速Web分页 让你的SQL数据库优化使之运行得更快 interoperate beneath C#基础概念二十五问 ASP.Net中利用CSS实现多界面两法【转自:中国站长站】 ASP.NET生成静态HTML页面并分别按年月目录存放[来自:中国站长站] - qjlyp
如何用C#编程方式批量对域控制器添加OU(http://topic.csdn.net/t/20051026/11/4351176.html)
qjlyp · 2007-08-20 · via 博客园 - qjlyp

【求助】如何用C#编程方式批量对域控制器添加OU

现在单位的部门(包括子部门)有上百个,之前做了一个管理系统已经有把机构存入数据库了,层次结构都有了,能否用编程方式读取数据库的数据,然后对应在域中添加OU,免得一个一个手动输入?  
   
  不够分可以再加。 问题点数:100、回复次数:11Top

1 楼luojinat2005()回复于 2005-10-26 12:33:19 得分 0

当然可以  
  能否说得具体一点  
  Top

2 楼xiaomatian(趴趴熊◎%#……※×)回复于 2005-10-26 13:38:30 得分 0

这个是肯定可以的.说具体点吧.Top

3 楼wqb1979(临风)回复于 2005-10-26 16:56:44 得分 0

就是怎么用C#向域控制器直接添加OU(组织机构)信息,因为现在在一个MIS系统的数据库里存放了我单位的组织机构信息,有上百个,我怎么一次性导入到域控制器里,关键就是怎么用System.DirectoryServices  
  Top

4 楼trumf(翦翦风)回复于 2005-10-26 17:27:53 得分 0

刚写个程序把域里所有的机器信息都用TreeView列出来了。  
  程序如下:  
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  DirectoryEntry   entry;  
  //   "WinNT://Domain"  
  String   strPath=@"WinNT://dpsd";  
  try    
  {  
  entry=new   DirectoryEntry(strPath);  
  TreeNode   users   =   new   TreeNode("Users");  
  TreeNode   groups   =   new   TreeNode("Groups");  
  TreeNode   services   =   new   TreeNode("Services");  
  viewPC.Nodes.Clear();   //   viewPC   is   a   TreeView   Componet  
  viewPC.Nodes.AddRange(new   TreeNode[]   {   users,   groups,   services   });  
   
  foreach(System.DirectoryServices.DirectoryEntry   child    
  in   entry.Children)    
  {  
  TreeNode   newNode   =   new   TreeNode(child.Name);  
  switch   (child.SchemaClassName)    
  {  
  case   "User"   :  
  users.Nodes.Add(newNode);        
  break;  
  case   "Group"   :  
  groups.Nodes.Add(newNode);        
  break;  
  case   "Service"   :  
  services.Nodes.Add(newNode);        
  break;  
  }  
  AddProperties(newNode,   child);  
  }  
  }    
  catch   (Exception   ex)    
  {  
  MessageBox.Show(   "err:"   +   ex.Message);  
  }  
  }  
   
  private   void   AddProperties(TreeNode   node,   System.DirectoryServices.DirectoryEntry   entry)  
  {  
  node.Nodes.Add(new   TreeNode("Path:   "   +   entry.Path));  
  TreeNode   propertyNode   =   new   TreeNode("Properties");  
  node.Nodes.Add(propertyNode);  
  foreach   (string   propertyName   in   entry.Properties.PropertyNames)    
  {  
  string   oneNode   =   propertyName   +   ":   "   +    
  entry.Properties[propertyName][0].ToString();  
  propertyNode.Nodes.Add(new   TreeNode(oneNode));  
  }  
  }Top

5 楼trumf(翦翦风)回复于 2005-10-26 17:30:51 得分 0

还有一些关于DirectoryServices的资料:  
   
  DirectoryEntry.Path   属性  
  获取或设置此   DirectoryEntry   的路径。  
   
    Path   属性唯一地标识网络环境中的此项。始终可以使用此   Path   检索此项。  
   
  设置   Path   将从目录存储区检索新项;它不更改当前绑定的项的路径。  
   
    与   DirectoryEntry   组件关 联的类可以与任何   Active   Directory   服务提供程序一起使用。当前的一些提供程序包括   Internet   信息服务   (IIS)、轻量目录访问协议   (LDAP)、Novell   NetWare   目录服务   (NDS)   和   WinNT。  
   
  注意         Path   的一部分,它标识提供程序(在“://”前面),并且区分大小写。例如,“LDAP://”或“WinNT://”。  
    Path   属性的语法随提供程序不同而不同。一些常见的情况有:  
   
  WinNT    
   
    连接到计算机上的组。例如“WinNT://<域名>/<计算机名>/<组名>”。如果是连接到本地计算机,则为“WinNT://<计算机名>/<组名>”。    
  连接到计算机上的用户。例如“WinNT://<域名>/<计算机名>/<用户名>”。如果是连接到本地计算机,则为“WinNT://<计算机名>/<用户名>”。    
  连接到计算机上的服务。例如,“WinNT://<域名>/<计算机名>/<服务名>”。如果是连接到本地计算机,则为“WinNT://<计算机名>/<服务名>”。    
  发现网络上的所有域。例如,“WinNT:”。通过枚举此项的子级可以找到这些域。    
  LDAP    
   
  连接到域中的组。例如“LDAP://CN=<组名>,   CN   =<用户>,   DC=<域控制器   1>,   DC=<域控制器   2>,...”。    
  连接到域中的用户。例如“LDAP://CN=<完整用户名>,   CN=<用户>,   DC=<域控制器   1>,   DC=<域控制器   2>,...”。    
  连接到域中的计算机。例如“LDAP://CN=<计算机名>,   CN=<计算机>,   DC=<域控制器   1>,   DC=<域控制器   2>,...”。    
  IIS    
   
  连接到   Web   目录。例如“IIS://LocalHost/W3SVC/1/ROOT/<Web   目录名>”。    
  若要使用   LDAP   绑定到当前域,请使用路径“LDAP://RootDSE”,然后获取默认命名上下文,并重新绑定该项。例如:  
   
  [C#]    
  String   str   =   ent.Properties["defaultNamingContext"][0];  
  DirectoryEntry   domain   =   new   DirectoryEntry("LDAP://"   +   str);  
     
  2.-----------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  WinNT   ADsPath  
   
  The   ADsPath   string   for   the   ADSI   WinNT   provider   can   be   one   of   the   following   forms:  
  "WinNT:"  
  "WinNT://<domain   name>"  
  "WinNT://<domain   name>/<server>"  
  "WinNT://<domain   name>/<path>"  
  "WinNT://<domain   name>/<object   name>"  
  "WinNT://<domain   name>/<object   name>,<object   class>"  
  The   domain   name   can   be   either   a   NETBIOS   name   or   a   DNS   name.  
   
  The   server   is   the   name   of   a   specific   server   within   the   domain.  
   
  The   path   is   the   path   of   on   object,   such   as   "printserver1/printer2".  
   
  The   object   name   is   the   name   of   a   specific   object.  
   
  The   object   class   is   the   class   name   of   the   named   object.   One   example   of   this   usage   would   be   "WinNT://MyDomain/JeffSmith,user".   Specifying   a   class   name   can   improve   the   performance   of   the   bind   operation.  
  Top

6 楼wqb1979(临风)回复于 2005-10-26 17:46:15 得分 0

to   trumf(翦翦风)    
  你实现了“读”功能,但我要导入ou,就是要涉及到写,如何“写”?Top

7 楼trumf(翦翦风)回复于 2005-10-27 09:00:21 得分 15

以下是往域里追加用户  
   
  private   void   AddUser(string   strDoamin,   string   strLogin,   string   strPwd)  
  {  
  DirectoryEntry   obDirEntry   =   null;  
  try  
  {  
  obDirEntry   =   new   DirectoryEntry("WinNT://"   +   strDoamin);  
  DirectoryEntries   entries   =   obDirEntry.Children;  
  DirectoryEntry   obUser   =   entries.Add(strLogin,   "User");  
  //obUser.Properties["FullName"].Add("Amigo");  
  object   obRet   =   obUser.Invoke("SetPassword",   strPwd);  
  obUser.CommitChanges();  
  }  
  catch   (Exception   ex)  
  {  
  Trace.Warn(ex.Message);  
  }  
  }  
   
    当然上栏列出的资料也列出了更改密码的方法。Top

8 楼fox7805034(肚子饿了)回复于 2005-10-27 09:12:38 得分 0

我加上一句。在《《c#高级编程》》里有针对ActiveDirectory的讲解。。。需要资料可以看看或googleTop

9 楼wqb1979(临风)回复于 2005-10-27 15:54:44 得分 0

加入OU能否也用DirectoryEntries.Add方法?参数怎么写?“OU”?Top

10 楼wqb1979(临风)回复于 2005-11-08 22:43:32 得分 0

我查了DirectoryEntries.Add的参数,发现第二参数:SchemaClassName有很多,继而查了微软在线的MSDN,发现添加OU的参数是:organizationUnit但还是不行呀Top

11 楼spgoal(敏捷的狗狗)回复于 2005-11-09 21:37:47 得分 85

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adam/adam/creating_organizational_units.asp  
   
  The   following   C#   code   example   in   uses   the   DirectoryEntry   constructor   to   bind   to   an   organization   object   and   uses   the   Add   method   to   create   an   organizationalUnit   object   in   that   organization.  
   
   
  using   System;  
  using   System.DirectoryServices;  
   
  namespace   ADAM_Examples  
  {  
          class   CreateOU  
          {  
                  ///   <summary>  
                  ///   Create   ADAM   Organizational   Unit.  
                  ///   </summary>  
                  [STAThread]  
                  static   void   Main()  
                  {  
                          DirectoryEntry   objADAM;     //   Binding   object.  
                          DirectoryEntry   objOU;         //   Organizational   unit.  
                          string   strDescription;       //   Description   of   OU.  
                          string   strOU;                         //   Organiztional   unit.  
                          string   strPath;                     //   Binding   path.  
   
                          //   Construct   the   binding   string.  
                          strPath   =   "LDAP://localhost:389/O=Fabrikam,C=US";  
   
                          Console.WriteLine("Bind   to:   {0}",   strPath);  
   
                          //   Get   ADAM   object.  
                          try  
                          {  
                                  objADAM   =   new   DirectoryEntry(strPath);  
                                  objADAM.RefreshCache();  
                          }  
                          catch   (Exception   e)  
                          {  
                                  Console.WriteLine("Error:       Bind   failed.");  
                                  Console.WriteLine("                   {0}",   e.Message);  
                                  return;  
                          }  
   
                          //   Specify   Organizational   Unit.  
                          strOU   =   "OU=TestOU";  
                          strDescription   =   "ADAM   Test   Organizational   Unit";  
                          Console.WriteLine("Create:     {0}",   strOU);  
   
                          //   Create   Organizational   Unit.  
                          try  
                          {  
                                  objOU   =   objADAM.Children.Add(strOU,  
                                          "OrganizationalUnit");  
                                  objOU.Properties["description"].Add(strDescription);  
                                  objOU.CommitChanges();  
                          }  
                          catch   (Exception   e)  
                          {  
                                  Console.WriteLine("Error:       Create   failed.");  
                                  Console.WriteLine("                   {0}",   e.Message);  
                                  return;  
                          }  
   
                          //   Output   Organizational   Unit   attributes.  
                          Console.WriteLine("Success:   Create   succeeded.");  
                          Console.WriteLine("Name:         {0}",   objOU.Name);  
                          Console.WriteLine("                   {0}",  
                                  objOU.Properties["description"].Value);  
                          return;  
                  }  
          }  
  }