




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、使用使用 C#C#批量修改域帐户信息全部代码批量修改域帐户信息全部代码本文关键字:本文关键字:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.DirectoryServices;namespace change/ / Form1 的摘要说明。/ public class Form1 : System.Windows.Forms.Formprivate Sy
2、stem.Windows.Forms.ComboBox comboBox2;private System.Windows.Forms.Label label3;private System.Windows.Forms.ComboBox comboBox1;private System.Windows.Forms.Label label2;string str=;string strErr=;string strManager=;private System.Windows.Forms.Label label1;private System.Windows.Forms.Label label4;
3、private System.Windows.Forms.Button button1;private System.Windows.Forms.TextBox textBox1;private System.Windows.Forms.TextBox textBox2;private System.Windows.Forms.TextBox textBox3;private System.Windows.Forms.CheckBox checkBox1;private System.Windows.Forms.CheckBox checkBox2;private System.Windows
4、.Forms.CheckBox checkBox3;private System.Windows.Forms.Label label5;private System.Windows.Forms.TextBox textBox4;private System.Windows.Forms.ComboBox comboBox3;private System.Windows.Forms.Label label6;private System.Windows.Forms.ComboBox comboBox4;private System.Windows.Forms.Label label7;privat
5、e System.Windows.Forms.ComboBox comboBox5;private System.Windows.Forms.Label label8;private System.Windows.Forms.ComboBox comboBox6;private System.Windows.Forms.Label label9;/ / 必需的设计器变量。/ private System.ComponentModel.Container components = null;public Form1()/ Windows 窗体设计器支持所必需的/InitializeCompone
6、nt();/ TODO: 在 InitializeComponent 调用后添加任何构造函数代码/ / 清理所有正在使用的资源。/ protected override void Dispose( bool disposing )if( disposing )if (components != null)components.Dispose();欢迎光临八一学习网八一学习网,收藏本篇文章收藏本篇文章$False$base.Dispose( disposing );#region Windows 窗体设计器生成的代码/ / 设计器支持所需的方法 - 不要使用代码编辑器修改/ 此方法的内容。/ p
7、rivate void InitializeComponent()boBox2 = new System.Windows.Forms.ComboBox();this.label3 = new System.Windows.Forms.Label();boBox1 = new System.Windows.Forms.ComboBox();this.label2 = new System.Windows.Forms.Label();this.label1 = new System.Windows.Forms.Label();this.label4 = new System.Windows.For
8、ms.Label();this.button1 = new System.Windows.Forms.Button();this.textBox1 = new System.Windows.Forms.TextBox();this.textBox2 = new System.Windows.Forms.TextBox();this.textBox3 = new System.Windows.Forms.TextBox();this.checkBox1 = new System.Windows.Forms.CheckBox();this.checkBox2 = new System.Window
9、s.Forms.CheckBox();this.checkBox3 = new System.Windows.Forms.CheckBox();this.label5 = new System.Windows.Forms.Label();this.textBox4 = new System.Windows.Forms.TextBox();boBox3 = new System.Windows.Forms.ComboBox();this.label6 = new System.Windows.Forms.Label();boBox4 = new System.Windows.Forms.Comb
10、oBox();this.label7 = new System.Windows.Forms.Label();boBox5 = new System.Windows.Forms.ComboBox();this.label8 = new System.Windows.Forms.Label();boBox6 = new System.Windows.Forms.ComboBox();this.label9 = new System.Windows.Forms.Label();this.SuspendLayout();/ comboBox2/boBox2.Location = new System.
11、Drawing.Point(416, 16);boBox2.Name = comboBox2;boBox2.Size = new System.Drawing.Size(121, 20);boBox2.TabIndex = 10;boBox2.SelectedIndexChanged += newSystem.EventHandler(boBox2_SelectedIndexChanged);/ label3/this.label3.Location = new System.Drawing.Point(320, 20);this.label3.Name = label3;this.label
12、3.Size = new System.Drawing.Size(80, 16);this.label3.TabIndex = 9;this.label3.Text = 文章整理文章整理: :八一学习网八一学习网 http:/http:/ (本站)选择部门(OU);/ comboBox1/boBox1.Location = new System.Drawing.Point(144, 16);boBox1.Name = comboBox1;boBox1.Size = new System.Drawing.Size(121, 20);boBox1.TabIndex = 8;boBox1.Selec
13、tedIndexChanged += newSystem.EventHandler(boBox1_SelectedIndexChanged);本文关键字:本文关键字:/ label2/this.label2.AutoSize = true;this.label2.Location = new System.Drawing.Point(40, 19);this.label2.Name = label2;this.label2.Size = new System.Drawing.Size(79, 17);this.label2.TabIndex = 7;this.label2.Text = 选择公
14、司(OU);/ label1/this.label1.Location = new System.Drawing.Point(48, 128);this.label1.Name = label1;this.label1.Size = new System.Drawing.Size(72, 23);this.label1.TabIndex = 11; this.label1.Text = 新公司名称;/ label4/this.label4.Location = new System.Drawing.Point(328, 128);this.label4.Name = label4;this.l
15、abel4.Size = new System.Drawing.Size(72, 23);this.label4.TabIndex = 12;this.label4.Text = 新部门名称;/ button1/this.button1.Location = new System.Drawing.Point(376, 376);this.button1.Name = button1;this.button1.TabIndex = 15;this.button1.Text = 开始处理;this.button1.Click += new System.EventHandler(this.butt
16、on1_Click);/ textBox1/this.textBox1.Location = new System.Drawing.Point(144, 128);this.textBox1.Name = textBox1;this.textBox1.Size = new System.Drawing.Size(120, 21);this.textBox1.TabIndex = 16;this.textBox1.Text = ;/ textBox2/this.textBox2.Location = new System.Drawing.Point(416, 128);this.textBox2
17、.Name = textBox2;this.textBox2.Size = new System.Drawing.Size(120, 21);this.textBox2.TabIndex = 17;this.textBox2.Text = ;/ textBox3/ 欢迎光临八一学习网八一学习网,点击这里点击这里查看更多文章教程this.textBox3.Location = new System.Drawing.Point(32, 232);this.textBox3.Multiline = true;this.textBox3.Name = textBox3;this.textBox3.Re
18、adOnly = true;this.textBox3.ScrollBars = System.Windows.Forms.ScrollBars.Both;this.textBox3.Size = new System.Drawing.Size(504, 120);this.textBox3.TabIndex = 18;this.textBox3.Text = ;/ checkBox1/this.checkBox1.Location = new System.Drawing.Point(64, 192);this.checkBox1.Name = checkBox1;this.checkBox
19、1.TabIndex = 20;this.checkBox1.Text = 修改公司名称;/ checkBox2/this.checkBox2.Location = new System.Drawing.Point(200, 192);this.checkBox2.Name = checkBox2;this.checkBox2.TabIndex = 21;this.checkBox2.Text = 修改部门名称;/ checkBox3/this.checkBox3.Location = new System.Drawing.Point(336, 192);this.checkBox3.Name
20、 = checkBox3;this.checkBox3.TabIndex = 22;this.checkBox3.Text = 修改部门领导;/ label5/this.label5.AutoSize = true;this.label5.Location = new System.Drawing.Point(40, 160);this.label5.Name = label5;this.label5.Size = new System.Drawing.Size(79, 17);this.label5.TabIndex = 19;this.label5.Text = 新的部门领导;/ text
21、Box4/this.textBox4.Location = new System.Drawing.Point(144, 160);this.textBox4.Name = textBox4;this.textBox4.Size = new System.Drawing.Size(392, 21);this.textBox4.TabIndex = 23;this.textBox4.Text = 请输入新领导的姓名全拼(域帐号);/ comboBox3/boBox3.Location = new System.Drawing.Point(144, 48);boBox3.Name = comboBo
22、x3;boBox3.Size = new System.Drawing.Size(121, 20);boBox3.TabIndex = 25;boBox3.SelectedIndexChanged += newSystem.EventHandler(boBox3_SelectedIndexChanged);/ label6/this.label6.AutoSize = true; this.label6.Location = new本文关键字:本文关键字:boBox5.Location = new System.Drawing.Point(416, 80);boBox5.Name = comb
23、oBox5;boBox5.Size = new System.Drawing.Size(121, 20);boBox5.TabIndex = 31;boBox5.SelectedIndexChanged += newSystem.EventHandler(boBox5_SelectedIndexChanged);/ label8/this.label8.Location = new System.Drawing.Point(280, 84);this.label8.Name = label8;this.label8.Size = new System.Drawing.Size(120, 16)
24、;this.label8.TabIndex = 30;this.label8.Text = 选择级五子部门(OU);/ comboBox6/boBox6.Location = new System.Drawing.Point(144, 80);boBox6.Name = comboBox6;boBox6.Size = new System.Drawing.Size(121, 20);boBox6.TabIndex = 29;boBox6.SelectedIndexChanged += newSystem.EventHandler(boBox6_Sele1234512345 ctedIndexC
25、hanged);/ label9/this.label9.AutoSize = true;this.label9.Location = new System.Drawing.Point(4, 83);this.label9.Name = label9;this.label9.Size = new System.Drawing.Size(116,欢迎光临八一学习网八一学习网,点点击这里击这里查看更多文章教程17);this.label9.TabIndex = 28;this.label9.Text = 选择四级子部门(OU);/ Form1/this.AutoScaleBaseSize = ne
26、w System.Drawing.Size(6, 14);this.ClientSize = new System.Drawing.Size(584, 429);this.Controls.Add(boBox5);this.Controls.Add(this.label8);this.Controls.Add(boBox6);this.Controls.Add(this.label9);this.Controls.Add(boBox4);this.Controls.Add(this.label7);this.Controls.Add(boBox3);this.Controls.Add(this
27、.label6);this.Controls.Add(this.textBox4);this.Controls.Add(this.checkBox3);this.Controls.Add(this.checkBox2);this.Controls.Add(this.checkBox1);this.Controls.Add(this.label5);this.Controls.Add(this.textBox3);this.Controls.Add(this.textBox2);this.Controls.Add(this.textBox1);this.Controls.Add(this.but
28、ton1);this.Controls.Add(this.label4);this.Controls.Add(this.label1);this.Controls.Add(boBox2);this.Controls.Add(this.label3);this.Controls.Add(boBox1);this.Controls.Add(this.label2);this.Name = Form1;this.Text = 按 OU 成批修改信息;this.Load += new System.EventHandler(this.Form1_Load);this.ResumeLayout(fals
29、e);#endregion/ / 应用程序的主入口点。/ static void Main()Application.Run(new Form1();private void comboBox1_SelectedIndexChanged(object sender,System.EventArgs e)/str=listBox1.SelectedItem.ToString();str=comboBox1.SelectedItem.ToString();DirectoryEntry de1=new DirectoryEntry();de1.Path=LDAP:/+str+,DC=test,DC=
30、net;trycomboBox2.Items.Clear();comboBox2.Text=;comboBox2.Refresh();foreach (DirectoryEntry ch1 in de1.Children)/textBox1.Text=textBox1.Text+str+rn;/ch.Properties.ToString();string str1=;str1=ch1.SchemaClassName 欢迎光临八一学习网八一学习网,收藏本篇文章收藏本篇文章.ToString();if (str1=organizationalUnit)comboBox2.Items.Add(ch
31、1.Name.ToString();de1.Close();/textBox1.Text=textBox1.Text+-next-rn;/ MessageBox.Show(finish!);catch(Exception ex)MessageBox.Show(ex.Message);finallyprivate void Form1_Load(object sender, S本文关键字:本文关键字:string strADRoot=;string strName=;if(comboBox1.Text=|comboBox2.Text=)strErr=请选择合适的 OU;goto e1;if(ch
32、eckBox1.Checked)if(textBox1.Text=)strErr=请输入新公司名称;goto e1;if(checkBox2.Checked)if(textBox2.Text=)strErr=请输入部门名称!;goto e1;if(checkBox3.Checked)if(textBox4.Text=请输入新领导的姓名全拼(域帐号))strErr=请输入新领导的姓名全拼(域帐号)!;goto e1;/ string strNewManager=;/搜索/检查是否有重复的帐号DirectoryEntry su=new DirectoryEntry(LDAP:/DC=test,DC
33、=net);DirectorySearcher searcher = new DirectorySearcher();searcher.SearchRoot=su;searcher.PropertiesT1234512345 oLoad.Add(CN);searcher.Filter =(&(objectClass=user)(sAMAccountName=+textBox4.Text.ToString()+);searcher.SearchScope = SearchScope.Subtree;searcher.Sort = new SortOption(sAMAccountName
34、,SortDirection.Ascending);SearchResultCollection results = searcher.FindAll();DialogResult dlResult;string strMess=您确认要将该 OU 下的用户的领导更改为:+results.Properties.ToString();dlResult=MessageBox.Show(this,strMess,请确认,MessageBoxButtons.YesNo,MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,MessageBox
35、Options.RightAlign);if(dlResult = DialogResult.Yes)strManager= results.Properties.ToString();strManager=strManager.Remove(0,7);elsetextBox4.Text=请重新输入新领导的姓名全拼(域帐号)!;strErr=请重新输入新领导的姓名全拼(域帐号)!;goto e1;if(!checkBox3.Checked)&(!checkBox2.Checked)&(!checkBox1.Checked)strErr=请选择要修改的项目!;goto e1;st
36、rADRoot=LDAP:/+str+,DC=test,DC=net;DirectoryEntry de=new DirectoryEntry();de.Path=strADRoot;textBox3.Text=;tryforeach(DirectoryEntry chm in de.Children)string strType=;strType=chm.SchemaClassName.ToString();if(strType.ToUpper()=USER)strName=chm.Name.ToString();/如果选中了修改领导的话欢迎光临八一学习网八一学习网,点击这里点击这里查看更多
37、文章教程if(checkBox3.Checked)if(chm.Properties.Contains(manager)chm.Properties=strManager;chm.CommitChanges();textBox3.Text=textBox3.Text+chm.Name .ToString()+的领导修改成功!rn;elsechm.Properties.Add(strManager);chm.CommitChanges();textBox3.Text=textBox3.Text+chm.Name .ToString()+的领导添加成功!rn;/修改公司if(checkBox1.C
38、hecked)if(chm.Properties.Contains(company)chm.Properties=textBox1.Text.ToString();chm.CommitChanges();textBox3.Text=textBox3.Text+chm.Name .ToString()+的公司名称修改成功!rn;elsechm.Properties.Add(textBox1.Text.ToString();chm.CommitChanges();textBox3.Text=textBox3.Text+chm.Name .ToString()+的公司名称添加成功!rn;/textB
39、ox3.Text=textBox3.Text+ch1.Name .ToString()+rn;/修改部门if(checkBox2.Checked)if(chm.Properties.Contains(department)chm.Properties=textBox2.Text.ToString();chm.CommitChanges();textBox3.Text=textBox3.Text+chm.Name .ToString()+的部门名称修改成功!rn;elsechm.Properties.Add(textBox2.Text.ToSt本文关键字:本文关键字:str=comboBox2.
40、SelectedItem.ToString()+,+comboBox1.SelectedItem.ToString();DirectoryEntry de1=new DirectoryEntry();de1.Path=LDAP:/+str+,DC=test,DC=net;trycomboBox3.Items.Clear();comboBox3.Text=;comboBox3.Refresh();foreach (DirectoryEntry ch1 in de1.Children)/textBox1.Text=textBox1.Text+str+rn;/ch.Properties.ToStri
41、ng();string str1=;str1=ch1.SchemaClassName.ToString();if (str1=organizationalUnit)comboBox3.Items.Add(ch1.Name.ToString();de1.Close();/textBox1.Text=textBox1.Text+-next-rn;/ MessageBox.Show(finish!);catch(Exception ex)MessageBox.Show(ex.Message);private void comboBox3_SelectedIndexChanged(object sen
42、der,System.EventArgs e)str=comboBox3.SelectedItem.ToString()+,+comboBox2.SelectedItem.ToString()+,+comboBox1.SelectedItem.ToString();DirectoryEntry de1=new DirectoryEntry();de1.Path=LDAP:/+str+,DC=test,DC=net;trycomboBox4.Items.Clear(1234512345 );comboBox4.Text=;comboBox4.Refresh();foreach (DirectoryEntry ch1 in de1.Children)/textBox1.Text=textBox1.Text+str+rn;/ch.Properties.ToString();string str1=;str1=ch1.SchemaClassName.ToString();if (str1=organizationalUnit)comboBox4.Items.Add(ch1.Name.ToString();de1.Close();/textBox1.Text=textBox1.Text+-next-rn;/ MessageBox.Show(finish
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 代理促销活动方案
- 代购年底活动方案
- 以旧换新电视机活动方案
- 仲裁服务活动方案
- 企业保护环境活动方案
- 企业严控聚集性活动方案
- 企业俱乐部活动方案
- 企业反腐活动方案
- 企业团员青年活动方案
- 企业奖励活动方案
- 希可欣肿瘤课件
- 【国标图集】13J404电梯自动扶梯自动人行道
- 居民死亡医学证明书英文翻译模板
- 2009-2022历年四川省乡镇定向公务员考试《行测》真题含答案2022-2023上岸必备汇编5
- 标识和可追溯性过程分析乌龟图
- 特种工作作业人员体格检查表
- 小学道德与法治人教五年级上册第四单元骄人祖先灿烂文化-《意蕴隽永的汉字》教学设计
- 关于赣州市登革热病例疫情的初步调查报告
- 网络舆论监督存在的问题及对策分析研究行政管理专业
- 普佑克四期临床方案
- 深圳实验学校小学毕业班数学试卷
评论
0/150
提交评论