public static CrPanel initalizeVariables()
        {
            CrPanel crp = new CrPanel();
            crp.DC.Text = "project.com";
            crp.DC.SelectedIndex = 1;//project.com
            crp.Groups.SelectedIndex = 1;//AMT
            crp.UserOU.SelectedIndex = 1;//CST
            crp.NumUsers.Text = "3";
            crp.FirstUser.Text = "100";

            crp.Password.Text = "password";
            crp.passwordLength.Text = "7";

            crp.HomeDrive.SelectedIndex = 0;
            crp.HomeDir.Text = @"\\Prjdc\vol1\";

            crp.ProfilePath.Text = @"\\Prjdc\vol1\";

            return crp;
        }
 /// <summary>
 /// Set all our local variables to values from our CrPanel
 /// </summary>
 /// <param name="cp">Current CrPanel we're working with</param>
 public void setVariables(CrPanel cp)
 {
     //Set the CrPanel variable
     setPanel(cp);
     //Set number of users variable
     setNumUsers();
     //Set first user int variable
     setFirstUser();
     //Set user ou variable
     setUserOU();
     //Set DC variable
     setDomainController();
     //Set password variable
     setPassword();
     //Set home drive variable
     setHomeDrive();
     //Set user prefix variable
     setUserPrefix();
     //Set group variable
     setGroup();
     //Set home directory variable
     setHomeDir();
     //set profile path variable
     setProfilePath();
     //Set password length variable
     setPasswordLength();
 }
 public void setPanel(CrPanel cp)
 {
     crm = cp;
 }
        /// <summary>
        /// Method to create Active Directory Users
        /// </summary>
        /// <param name="cp">Reference to get information from Properties</param>
        public void createUsers(CrPanel cp)
        {
            setVariables(cp);
            users = new Queue<string>();
            ProgressWindow pwProgress = new ProgressWindow("Creating Users...", iNumUsers);

            try
            {
                crm.CreateButton.Enabled = false;
                string oGUID = string.Empty;
                string ldapPath = sUserOU;
                //Set hte connection prefix
                string connectionPrefix = ldapPath;
                //Get a directoryEntry object from the OU
                DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
                //Reset the output string
                this.output = "";

                //Creates a progress bar window for user to see how creation is progressing
                pwProgress.Show();
                pwProgress.SetPercentDone(0);

                //Foreach number of users defined
                for (int i = iFirstUser; i < (iFirstUser +  iNumUsers); i++)
                {
                    pwProgress.SetPercentDone(i-iFirstUser);
                    //Define the username
                    string userName = sUserPrefix + i;
                    //Define DirectoryEntry obejct for the new user
                    DirectoryEntry newUser = dirEntry.Children.Add
                        ("CN=" + userName, "user");
                    //Set the user's properties
                    setUserProperties(newUser, userName, i, "");
                }
                //close progress bar window
                pwProgress.Close();
                //Create the file and append the output to the file
                System.IO.StreamWriter file = new System.IO.StreamWriter(this.sUserPrefix + ".txt", false);
                file.WriteLine(output);
                users.Enqueue(output);
                //Close the file
                file.Close();
                //Write files to word doc, not included because server currently doesn't have Word
                //WriteUserDoc();
                MessageBox.Show("Users have been created Successfully");
            }
            catch (System.DirectoryServices.DirectoryServicesCOMException E)
            {
                MessageBox.Show(E.Message);
                //close progress bar window
                pwProgress.Close();

            }
        }
        /// <summary>
        /// Method to create a set of extension accounts
        /// </summary>
        /// <param name="cp">Current CrPanel we're working with</param>
        public void createExtUsers(CrPanel cp)
        {
            //Set our variables
            setVariables(cp);
            //Check if the extension has an appended number
            int appendNum = -1;
            try
            {
                appendNum = int.Parse("" + sUserPrefix.ElementAt(sUserPrefix.Length - 1));
            }
            catch(Exception e)
            {
                Console.WriteLine("Must have user prefix ext#");
            }
            try
            {
                //Verify that the EXT# prefix is included
                if (sUserPrefix.ToUpper().IndexOf("EXT") > -1
                    &&  appendNum >= 0)
                {
                    crm.CreateExtButton.Enabled = false;
                    string oGUID = string.Empty;
                    string ldapPath = sUserOU;
                    string connectionPrefix = ldapPath;

                    //Define the allowed letters that we will use
                    string sAllowedChars = "abcdefghjkmnpqrstuvwxyz";
                    //Get our OU directoryEntry object
                    DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
                    //Foreach letter in the allowed characters defined above
                    for (int k = 0; k < sAllowedChars.Length; k++)
                    {
                        this.output = "";

                        //Set the current extension letter
                        char currExtLetter = sAllowedChars.ElementAt(k);
                        //Loop through the number of users per letter
                        for (int i = iFirstUser; i < (iFirstUser + iNumUsers); i++)
                        {
                            //Define the userName
                            string userName = sUserPrefix + currExtLetter + i;
                            //Get the DirectoryEntry for our new user
                            DirectoryEntry newUser = dirEntry.Children.Add
                                ("CN=" + userName, "user");
                            //Set all the user's properties
                            setUserProperties(newUser, userName, i, currExtLetter.ToString());
                        }
                        //Create the file and append the output to the file
                        System.IO.StreamWriter file = new System.IO.StreamWriter(this.sUserPrefix + currExtLetter + ".txt", false);
                        file.WriteLine(output);
                        users.Enqueue(output);
                        //Close the file
                        file.Close();
                    }
                    MessageBox.Show("Users have been created Successfully");

                }
                else
                {
                    MessageBox.Show("Extension accounts must have the ext# prefix");
                }
            }
            catch (System.DirectoryServices.DirectoryServicesCOMException E)
            {
                MessageBox.Show(E.Message);

            }
        }