示例#1
0
        public static List <Computers> GetComputerNames(string domain, string systemtype)
        {
            List <Computers> computers     = new List <Computers>();
            GetComputers     ComputerNames = new GetComputers();
            //string domain = Environment.UserDomainName;
            DirectoryEntry    entry      = new DirectoryEntry("LDAP://" + domain);
            DirectorySearcher mySearcher = new DirectorySearcher(entry);

            mySearcher.Filter    = ("(objectClass=computer)");
            mySearcher.SizeLimit = int.MaxValue;
            mySearcher.PageSize  = int.MaxValue;
            foreach (SearchResult resEnt in mySearcher.FindAll())
            {
                //          List<object> ComputerObject;
                //          List<str>

                if (resEnt.Properties["operatingsystem"] != null && resEnt.Properties["operatingsystem"].Count > 0)
                {
                    string OS   = resEnt.Properties["operatingsystem"][0].ToString();
                    string type = "";
                    if (systemtype == "Servers" && OS.Contains("Server"))
                    {
                        string ComputerName = resEnt.GetDirectoryEntry().Name;

                        if (ComputerName.StartsWith(type))
                        {
                            if (ComputerName.StartsWith("CN="))
                            {
                                ComputerName = ComputerName.Remove(0, "CN=".Length);
                            }
                            computers.Add(new Computers()
                            {
                                ComputerName = ComputerName
                            });
                        }
                    }
                    else if (systemtype == "Computers" && !OS.Contains("Server"))
                    {
                        string ComputerName = resEnt.GetDirectoryEntry().Name;

                        if (ComputerName.StartsWith(type))
                        {
                            if (ComputerName.StartsWith("CN="))
                            {
                                ComputerName = ComputerName.Remove(0, "CN=".Length);
                            }
                            computers.Add(new Computers()
                            {
                                ComputerName = ComputerName
                            });
                        }
                    }
                }
            }

            mySearcher.Dispose();
            entry.Dispose();

            return(computers.OrderBy(x => x.ComputerName).ToList <Computers>());
        }
示例#2
0
        private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (comboBox2.SelectedItem.ToString() == null)
            {
                comboBox2.SelectedItem = "Servers";
            }
            string systemtypeselected = comboBox2.SelectedItem.ToString();
//            string domain = comboBox1.SelectedText;
            string           domain = comboBox1.SelectedValue.ToString();
            List <Computers> ChangedcomputerList = GetComputers.GetComputerNames(domain, systemtypeselected);

            listBox1.DataSource    = ChangedcomputerList;
            listBox1.DisplayMember = "ComputerName";
            listBox1.Update();
        }
示例#3
0
        private void Form1_Load(object sender, EventArgs e)
        {
/*          string domain = "domain";
 *          List<Computers> computerList = GetComputers.GetComputerNames(domain);
 *          comboBox1.DisplayMember = "ComputerName";
 *          comboBox1.DataSource = computerList;
 */
            List <Domains> domainList = GetDomains.GetDomainNames();
            string         domain     = domainList[0].DomainName;

            comboBox1.SelectedText  = "Domain Name";
            comboBox1.SelectedItem  = "Domain Name";
            comboBox1.SelectedValue = "Domain Name";
            comboBox1.ValueMember   = "DomainName";
            comboBox1.DataSource    = domainList;
            comboBox2.SelectedText  = "Servers";
            comboBox2.SelectedValue = "Servers";
            comboBox2.SelectedItem  = "Servers";
            List <Computers> computerList = GetComputers.GetComputerNames(domain, "Servers");

            listBox1.DisplayMember = "ComputerName";
            listBox1.DataSource    = computerList;
        }
示例#4
0
 private void comboBox2_SelectionChangeCommitted(object sender, EventArgs e)
 {
     {
         string firstdomain = domainList[0].DomainName;
         string selecteddomain;
         string cb1Text = comboBox1.SelectedValue.ToString();
         if (cb1Text == "")
         {
             comboBox1.SelectedText  = firstdomain;
             comboBox1.SelectedItem  = firstdomain;
             comboBox1.SelectedValue = firstdomain;
             selecteddomain          = firstdomain;
         }
         else
         {
             selecteddomain = cb1Text;
         }
         string           systemtypeselected  = comboBox2.SelectedItem.ToString();
         List <Computers> ChangedcomputerList = GetComputers.GetComputerNames(selecteddomain, systemtypeselected);
         listBox1.DataSource    = ChangedcomputerList;
         listBox1.DisplayMember = "ComputerName";
         listBox1.Update();
     }
 }