using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.DirectoryServices; namespace change {///
/// summary> private system.componentmodel.container Components = NULL; Public Form1 () {// // Windows Form Designer Support To Support // InitializationComponent (); // // Todo: Call in InitializationComponent Add any constructor code //} ///
/// 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.form S.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.Selected IndexChanged = new system.eventhandler (this.comboBox2_selected);
/// 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 = "Select department (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 = "Select Company (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 = "New Company Name"; // // 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 = "new department name"; // // button1 // this.button1.location = New system.drawing.point (376, 376); this.button1.name = "button1"; this.button1.tabindex = 15; this.button1.text = "Start processing"; this.button1.click = new system . EventHandler (this.button1_click);
//////////////////////////////Wwndrawing.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.tabinde x = 20; this.checkbox1.text = "Modify the company name"; //// Checkbox2 // this.checkbox2.location = new system.drawing.point (200, 192); this.checkbox2.name = "checkbox2" This.checkbox2.tabindex = 21; this.checkbox2.text = "Modified Department Name"; /// CheckBox3 // this.checkbox3.location = new system.drawing.point (336, 192); this.checkbox3. Name = "checkbox3"; this.checkbox3.tabindex = 22; this.checkbox3.text = "Modify department leadership"; // // 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 = "New Department Leaders"; ////////////////////////////////////////////////////////////////////////bitBox4.point = 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 = "Please enter the new leader's name (domain account)"; // // 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.tex T = "Select the secondary sub-department (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 );
THISLABEL7.TABINDEX = 26; this.label7.text = "Select the three sub-department (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 = "Select stage five sub-sector (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_selected); // // 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 = "Select the four sub-department (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 ( THISCHECKBOX2; 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 = " Press OU Batch Modification Information "; this.Load = New System.EventHandler (this.form1_load); this.ResumeLayout (false);} #ENDREGION ///
/// 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.Tostring (ch1.name.tostring )));}} De1.close (); //textbox1.text=textBox1.text "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------- / r / n; // MessageBox.show ("Finish !!!");} catch (exception ex) {messagebox.show (ex.Message);} finally {} } Private void form1_load (Object Sender, System.EventArgs e) {// Initialization Company selection box 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.toTostring (); string string STR = ""; //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 "-------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------- / r / n "; // MessageBox.show (" Finish !!! ");} catch (exception ex) {strerr = ex. amount;} finally {}} private void button1_click Object sender, system.eventargs e) {string stradroot = ""; string strname = ""; if (comboBoX1.text == "|| combobox2.text ==") {strerr = "Please select the right OU" Goto E1;} if (checkbox1.checked) {if (TextBox1.text == ") {strerr =" Please enter the new company name "; goto E1;}} f (checkbox2.checked) {if (TextBox2.text == "" "{STRERR =" Please enter the department name! "; Goto E1;}} if (checkbox3.checked) {if (TextBox4.text ==" Please enter the new leader's name full (domain account) ") {Strerr = "Please enter the new leader's name (domain account)!"; Goto E1;} // String strnewmanager = ""; // Search // Check if there is a repetitive account 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 = "You confirm that you want to change the user's leadership's leadership to:" Results [0] .properties ["cn"] [0] .toString () ; dlResult = MessageBox.Show (this, strMess, "Please confirm", 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 = "Please re-enter the new leader's name full (domain account)!"; Strerr = "Please re-enter the new leader's name full (domain account)!"; Goto e1;}} && (! Checkbox2.checked) && (! Checkbox1.checked) {strro = " Please select the item you want to modify! "; Goto E1;} stradroot =" ldap: // " Str ", DC = TEST, DC = Net "; DirectoryEntry de = new DirectoryEntry (); de.path = stradroot; TextBox3. TEXT = ""; try {finach (directren) {string str. = ""; Startpe = chm.schemaclassname.tostring (); if (strtype.toupper () == "user") {STRNAME = chm.name.toString (); // If you select the modified leadership if (checkbox3.checked) {if (chm.properties.contains ("manager")) {chm.properties ["manager"] [0 ] = STRMANAGER; chm.commitchanges (); TextBox3.text = TextBox3.text chm.name .tostring () "leaders to modify! / r / n ";} else {chm.properties [" manager "]. Add (strmanager); chm.commitchanges ();
TextBox3.text = TextBox3.text chm.name .tostring () "Leadership Add success! / r / n";}} // Modify company if (checkbox1.checked) {if (chm.properties.contains (" Company ")] {chm.properties [" Company "] [0] = textbox1.text.toString (); chm.commitchanges (); textbox3.text = textbox3.text chm.name .tostring () " company Name modification success! / R / n ";} else {chm.properties [" company "]. Add (TextBox1.text.toString ()); chm.commitchanges (); TextBox3.text = TextBox3.text chm.name .Tostring () "company name adds success! / R / n"; //textbox3.text=textBox3.text ch1.name .tostring () "/ r / n";}} // Modify department IF (CHM.Properties.Contains ("department")) {chm.properties ["divartment"] [0] = textbox2.text.toString (); chm.commitchanges (); textbox3.text = TextBox3.text chm.name.tostring () "department name modification success! / r / n";} else {chm.properties ["department"]. add (TextBox2.text.toString ()); chm. Commitchanges (); //textbox3.t EXT = TextBox3.text ch1.Name .tostring () "/ r / n"; TextBox3.text = TextBox3.text chm.name .tostring () "department name is successful! / r / n ";}}}} messagebox.show (" Modified success! ");} catch (exception ex) {strerr = ex. amount; 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 () " " "DirectoryEntry de1 = new directoryEntry de1 = new directoryEntry (); de1.path =" ldap: // " str ", DC = test, DC = Net " {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 Directorynt Ry (); 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 "----------------------- ------- / 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.toTString () ", " ComboBoX1.SelectedItem.tostring (); DirectoryEntry DE1 =