- 浏览: 821530 次
-
文章分类
最新评论
-
coosummer:
推荐使用http://buttoncssgenerator.c ...
几个漂亮的Button的CSS -
leonardleonard:
现在网站 放到 windows 2008 貌似 攻击少了
网站常被攻击 -
leonardleonard:
复制的
在C#里实现DATAGRID的打印预览和打印 -
spp_1987:
看着 头疼 本来就是头难受
在C#里实现DATAGRID的打印预览和打印 -
spp_1987:
大哥 代码太乱啊 ???
在C#里实现DATAGRID的打印预览和打印
公司的组织结构经常发生变化,而我们的域帐户信息(AD)是和真实的组织机构相对应的。组织机构变化了,我们自然要改动相应的域帐户信息啦。这是一件很痛苦的事情,原因是什么,大家都明白。那么能不能用程序来解决这个问题呢?(windows2003的管理工具好像已经支持批量修改域帐户信息了)。
我创建了一个windows应用程序来解决:
在Form上放置了六个comboBox用于选择公司的OU(可以选择五级OU,如果你喜欢可以用TreeView更好些)。
加载Form的时候初始化这些comboBox:
private void Form1_Load(object sender, System.EventArgs e)
{
//初始化公司选择框
DirectoryEntry de1=new DirectoryEntry();
de1.Path="LDAP://DC=test,DC=net";
try
{
//所有OU(第一级)
foreach (DirectoryEntry ch1 in de1.Children)
{
str=ch1.Name.ToString();
string str1="";
//str1=str.Substring(0,str.IndexOf("="));
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
//listBox1.Items.Add(ch1.Name.ToString());
//加入第一个combobox
comboBox1.Items.Add(ch1.Name.ToString());
//
comboBox3.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
//
MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
strErr=ex.Message;
}
finally
{}
}
在初始化form的时候在第一个combobox中显示出所有的第一层OU。然后,在选择了这个combobox的时候,在第二个combobox中显示下一级OU:
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=net";
try
{
comboBox2.Items.Clear();
comboBox2.Text="";
comboBox2.Refresh();
foreach (DirectoryEntry ch1 in de1.Children)
{
//
textBox1.Text=textBox1.Text+str+"\r\n";//ch.Properties["adpath"][0].ToString();
string str1="";
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
comboBox2.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
//
MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{}
}
依次在下一个combobox中显示下一级OU。选择好要修改的OU下后,就可以修改该ou下所有的信息了。这里以修改部门名称为例。
使用一个Textbox输入部门名称,放一个按钮触发修改动作:
private void button1_Click(object sender, System.EventArgs e)
{
string strADRoot="";
string strName="";
//str中保存的是OU的ADPath的一部分,即通过选择combobox产生的字符串,类似于ou=imd,OU=company
strADRoot="LDAP://"+str+",DC=test,DC=net";
DirectoryEntry de=new DirectoryEntry();
de.Path=strADRoot;
//修改所有的user对象
foreach(DirectoryEntry chm in de.Children)
{
string strType="";
strType=chm.SchemaClassName.ToString();
if(strType.ToUpper()=="USER")
{
strName=chm.Name.ToString();
//判断是否属性值是否为空
if(chm.Properties.Contains("department"))
{
chm.Properties["department"][0]=textBox2.Text.ToString();
chm.CommitChanges();
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的部门名称修改成功!\r\n";
}
else
{
chm.Properties["department"].Add(textBox2.Text.ToString());
chm.CommitChanges();
//textBox3.Text=textBox3.Text+ch1.Name .ToString()+"\r\n";
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的部门名称添加成功!\r\n";
}
}
}
全部代码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.DirectoryServices;
namespace change
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.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;
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.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;
private System.Windows.Forms.ComboBox comboBox5;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.ComboBox comboBox6;
private System.Windows.Forms.Label label9;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.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.Windows.Forms.CheckBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.comboBox3 = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.comboBox4 = new System.Windows.Forms.ComboBox();
this.label7 = new System.Windows.Forms.Label();
this.comboBox5 = new System.Windows.Forms.ComboBox();
this.label8 = new System.Windows.Forms.Label();
this.comboBox6 = new System.Windows.Forms.ComboBox();
this.label9 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// comboBox2
//
this.comboBox2.Location = new System.Drawing.Point(416, 16);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 20);
this.comboBox2.TabIndex = 10;
this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
//
// label3
//
this.label3.Location = new System.Drawing.Point(320, 20);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 16);
this.label3.TabIndex = 9;
this.label3.Text = "选择部门(OU)";
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(144, 16);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 8;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_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 = "选择公司(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.label4.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.button1_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.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.ReadOnly = 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.checkBox1.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 = "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 = "新的部门领导";
//
// textBox4
//
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
//
this.comboBox3.Location = new System.Drawing.Point(144, 48);
this.comboBox3.Name = "comboBox3";
this.comboBox3.Size = new System.Drawing.Size(121, 20);
this.comboBox3.TabIndex = 25;
this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(4, 51);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(116, 17);
this.label6.TabIndex = 24;
this.label6.Text = "选择二级子部门(OU)";
//
// comboBox4
//
this.comboBox4.Location = new System.Drawing.Point(416, 48);
this.comboBox4.Name = "comboBox4";
this.comboBox4.Size = new System.Drawing.Size(121, 20);
this.comboBox4.TabIndex = 27;
this.comboBox4.SelectedIndexChanged += new System.EventHandler(this.comboBox4_SelectedIndexChanged);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(284, 51);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(116, 17);
this.label7.TabIndex = 26;
this.label7.Text = "选择三级子部门(OU)";
//
// comboBox5
//
this.comboBox5.Location = new System.Drawing.Point(416, 80);
this.comboBox5.Name = "comboBox5";
this.comboBox5.Size = new System.Drawing.Size(121, 20);
this.comboBox5.TabIndex = 31;
this.comboBox5.SelectedIndexChanged += new System.EventHandler(this.comboBox5_SelectedIndexChanged);
//
// label8
//
this.label8.Location = new System.Drawing.Point(280, 84);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(120, 16);
this.label8.TabIndex = 30;
this.label8.Text = "选择级五子部门(OU)";
//
// comboBox6
//
this.comboBox6.Location = new System.Drawing.Point(144, 80);
this.comboBox6.Name = "comboBox6";
this.comboBox6.Size = new System.Drawing.Size(121, 20);
this.comboBox6.TabIndex = 29;
this.comboBox6.SelectedIndexChanged += new System.EventHandler(this.comboBox6_SelectedIndexChanged);
//
// 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 = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(584, 429);
this.Controls.Add(this.comboBox5);
this.Controls.Add(this.label8);
this.Controls.Add(this.comboBox6);
this.Controls.Add(this.label9);
this.Controls.Add(this.comboBox4);
this.Controls.Add(this.label7);
this.Controls.Add(this.comboBox3);
this.Controls.Add(this.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.button1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.label3);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label2);
this.Name = "Form1";
this.Text = "按OU成批修改信息";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
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=net";
try
{
comboBox2.Items.Clear();
comboBox2.Text="";
comboBox2.Refresh();
foreach (DirectoryEntry ch1 in de1.Children)
{
// textBox1.Text=textBox1.Text+str+"\r\n";//ch.Properties["adpath"][0].ToString();
string str1="";
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
comboBox2.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
// MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{}
}
private void Form1_Load(object sender, System.EventArgs e)
{
//初始化公司选择框
DirectoryEntry de1=new DirectoryEntry();
de1.Path="LDAP://DC=test,DC=net";
try
{
foreach (DirectoryEntry ch1 in de1.Children)
{
// textBox1.Text=textBox1.Text+ch1.Name+"\r\n";//ch.Properties["adpath"][0].ToString();
str=ch1.Name.ToString();
string str1="";
//str1=str.Substring(0,str.IndexOf("="));
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
//listBox1.Items.Add(ch1.Name.ToString());
comboBox1.Items.Add(ch1.Name.ToString());
// comboBox3.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
// MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
strErr=ex.Message;
}
finally
{}
}
private void button1_Click(object sender, System.EventArgs e)
{
string strADRoot="";
string strName="";
if(comboBox1.Text==""||comboBox2.Text=="")
{
strErr="请选择合适的OU";
goto e1;
}
if(checkBox1.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=net");
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot=su;
searcher.PropertiesToLoad.Add("CN");
searcher.Filter = "(&(objectClass=user)(sAMAccountName="+textBox4.Text.ToString()+"))";
searcher.SearchScope = SearchScope.Subtree;
searcher.Sort = new SortOption("sAMAccountName", SortDirection.Ascending);
SearchResultCollection results = searcher.FindAll();
DialogResult dlResult;
string strMess="您确认要将该OU下的用户的领导更改为:"+results[0].Properties["CN"][0].ToString();
dlResult=MessageBox.Show(this,strMess,"请确认",MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if(dlResult == DialogResult.Yes)
{
strManager= results[0].Properties["adspath"][0].ToString();
strManager=strManager.Remove(0,7);
}
else
{
textBox4.Text="请重新输入新领导的姓名全拼(域帐号)!";
strErr="请重新输入新领导的姓名全拼(域帐号)!";
goto e1;
}
}
if((!checkBox3.Checked)&&(!checkBox2.Checked)&&(!checkBox1.Checked))
{
strErr="请选择要修改的项目!";
goto e1;
}
strADRoot="LDAP://"+str+",DC=test,DC=net";
DirectoryEntry de=new DirectoryEntry();
de.Path=strADRoot;
textBox3.Text="";
try
{
foreach(DirectoryEntry chm in de.Children)
{
string strType="";
strType=chm.SchemaClassName.ToString();
if(strType.ToUpper()=="USER")
{
strName=chm.Name.ToString();
//如果选中了修改领导的话
if(checkBox3.Checked)
{
if(chm.Properties.Contains("manager"))
{
chm.Properties["manager"][0]=strManager;
chm.CommitChanges();
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的领导修改成功!\r\n";
}
else
{
chm.Properties["manager"].Add(strManager);
chm.CommitChanges();
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的领导添加成功!\r\n";
}
}
//修改公司
if(checkBox1.Checked)
{
if(chm.Properties.Contains("company"))
{
chm.Properties["company"][0]=textBox1.Text.ToString();
chm.CommitChanges();
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的公司名称修改成功!\r\n";
}
else
{
chm.Properties["company"].Add(textBox1.Text.ToString());
chm.CommitChanges();
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的公司名称添加成功!\r\n";
//textBox3.Text=textBox3.Text+ch1.Name .ToString()+"\r\n";
}
}
//修改部门
if(checkBox2.Checked)
{
if(chm.Properties.Contains("department"))
{
chm.Properties["department"][0]=textBox2.Text.ToString();
chm.CommitChanges();
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的部门名称修改成功!\r\n";
}
else
{
chm.Properties["department"].Add(textBox2.Text.ToString());
chm.CommitChanges();
//textBox3.Text=textBox3.Text+ch1.Name .ToString()+"\r\n";
textBox3.Text=textBox3.Text+chm.Name .ToString()+"的部门名称添加成功!\r\n";
}
}
}
}
MessageBox.Show("修改成功!");
}
catch(Exception ex)
{
strErr=ex.Message;
goto e1;
}
e1: if(strErr!="")
{
MessageBox.Show(strErr);
}
}
private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
//str=listBox1.SelectedItem.ToString();
str=comboBox2.SelectedItem.ToString()+","+comboBox1.SelectedItem.ToString();
DirectoryEntry de1=new DirectoryEntry();
de1.Path="LDAP://"+str+",DC=test,DC=net";
try
{
comboBox3.Items.Clear();
comboBox3.Text="";
comboBox3.Refresh();
foreach (DirectoryEntry ch1 in de1.Children)
{
// textBox1.Text=textBox1.Text+str+"\r\n";//ch.Properties["adpath"][0].ToString();
string str1="";
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
comboBox3.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
// MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void comboBox3_SelectedIndexChanged(object sender, 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";
try
{
comboBox4.Items.Clear();
comboBox4.Text="";
comboBox4.Refresh();
foreach (DirectoryEntry ch1 in de1.Children)
{
// textBox1.Text=textBox1.Text+str+"\r\n";//ch.Properties["adpath"][0].ToString();
string str1="";
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
comboBox4.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
// MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void comboBox4_SelectedIndexChanged(object sender, System.EventArgs e)
{
str=comboBox4.SelectedItem.ToString()+","+comboBox3.SelectedItem.ToString()+","+comboBox2.SelectedItem.ToString()+","+comboBox1.SelectedItem.ToString();
DirectoryEntry de1=new DirectoryEntry();
de1.Path="LDAP://"+str+",DC=test,DC=net";
try
{
comboBox6.Items.Clear();
comboBox6.Text="";
comboBox6.Refresh();
foreach (DirectoryEntry ch1 in de1.Children)
{
// textBox1.Text=textBox1.Text+str+"\r\n";//ch.Properties["adpath"][0].ToString();
string str1="";
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
comboBox6.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
// MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void comboBox6_SelectedIndexChanged(object sender, System.EventArgs e)
{
str=comboBox6.SelectedItem.ToString()+","+comboBox4.SelectedItem.ToString()+","+
comboBox3.SelectedItem.ToString()+","+comboBox2.SelectedItem.ToString()+","+
comboBox1.SelectedItem.ToString();
DirectoryEntry de1=new DirectoryEntry();
de1.Path="LDAP://"+str+",DC=test,DC=net";
try
{
comboBox5.Items.Clear();
comboBox5.Text="";
comboBox5.Refresh();
foreach (DirectoryEntry ch1 in de1.Children)
{
// textBox1.Text=textBox1.Text+str+"\r\n";//ch.Properties["adpath"][0].ToString();
string str1="";
str1=ch1.SchemaClassName.ToString();
if (str1=="organizationalUnit")
{
comboBox5.Items.Add(ch1.Name.ToString());
}
}
de1.Close();
//textBox1.Text=textBox1.Text+"--------------next------------------------\r\n";
// MessageBox.Show("finish!!!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void comboBox5_SelectedIndexChanged(object sender, System.EventArgs e)
{
str=comboBox5.SelectedItem.ToString()+","+comboBox6.SelectedItem.ToString()+","+comboBox4.SelectedItem.ToString()+","+
comboBox3.SelectedItem.ToString()+","+comboBox2.SelectedItem.ToString()+","+
comboBox1.SelectedItem.ToString();
}
}
}
相关推荐
9. **枚举域成员**:遍历域中的所有成员,如用户、组和计算机,可以用于批量操作或报告生成。 10. **处理错误和异常**:提供适当的错误处理机制,确保在遇到问题时能够适当地捕获和报告异常。 为了确保代码的质量...
在IT领域,活动目录(Active Directory,简称AD)是微软Windows服务器操作系统中的一个核心组件,用于管理和存储有关网络资源的信息,如用户账户、计算机、安全策略等。在.NET框架下,开发人员可以使用C#语言来操作...
在Active Directory(AD)环境中,用户账户是组织结构的核心元素,包含了关于员工、合作伙伴或任何需要访问网络资源的用户的详细信息。用户属性是定义这些账户特性的关键元素,理解它们对于管理和维护AD至关重要。...
2. **注册与账户创建**:新用户需要填写相关信息创建账户,这些信息可能包括姓名、电子邮件地址、联系方式等。系统会验证这些信息的有效性,并将它们存储在数据库中。 3. **密码管理**:用户应能修改密码,如果忘记...
C#编程经验技巧宝典源代码,目录如下: 第1章 开发环境 1 <br>1.1 Visual Studio开发环境安装与配置 2 <br>0001 安装Visual Studio 2005开发环境须知 2 <br>0002 配置合适的Visual Studio 2005...
- **自动化用户账户管理**:编写代码自动创建、启用、禁用用户账户,批量修改用户属性。 - **组策略对象(GPO)**:学习如何利用C#脚本应用和管理组策略,控制用户和计算机的配置。 - **事件日志和审计**:通过C#...
1. **查询目录信息**:通过使用ADSI对象模型,可以查询活动目录中的用户、计算机、组等对象的信息,如用户名、全名、账户状态等。 2. **修改目录对象**:不仅可以读取对象属性,还能修改它们。例如,可以更改用户...
这允许管理员在任何有网络连接的地方对FTP服务器进行配置,包括添加、删除和修改用户账户,设置权限,监控服务器状态等。 3. **FTP用户管理** 在Serv-U中,用户管理是核心功能之一。管理员可以创建多个用户账户,...
通过学习本书的PowerShell章节,读者将能够编写脚本来执行批量的Active Directory管理任务,如用户账户创建、组成员管理等。 ### 三、高级主题 #### 3.1 安全性和权限管理 安全性和权限管理是Active Directory的...
【批量操作性能优化】批量添加、删除和修改数据时,应尽量减少数据库交互次数,可以使用事务处理,一次性提交大量操作,避免频繁的SQL查询影响性能。 【字符串反转】不使用库函数将"I am a student"反转为"Student ...
访问器是在C#等语言中用来读取或修改类成员的函数。通常有两种类型:getter和setter。前者用于获取成员的值,后者则用于设置成员的值。 #### 操作 (Action) 操作通常指的是由用户触发的一个事件或者系统自动执行的...
- **应用场景**:类的封装、保护内部数据不被外部直接修改。 **8. Access Function 访问函数** - **定义**:用于获取或设置类的私有成员变量的函数。 - **应用场景**:增强类的安全性,通过公共接口访问私有数据。 ...