Esempio n. 1
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;
        }
Esempio n. 2
0
        public static List <Domains> GetDomainNames()
        {
            List <Domains> domains     = new List <Domains>();
            GetDomains     DomainNames = new GetDomains();

/*            string domain = Environment.UserDomainName;
 *          DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
 *          DirectorySearcher mySearcher = new DirectorySearcher(entry);
 *          mySearcher.Filter = ("(objectClass=domain)");
 *          mySearcher.SizeLimit = int.MaxValue;
 *          mySearcher.PageSize = int.MaxValue;
 */         using (var forest = Forest.GetCurrentForest())
            {
                foreach (Domain mydomain in forest.Domains)
                {
                    domains.Add(new Domains()
                    {
                        DomainName = mydomain.Name
                    });
                    mydomain.Dispose();
                }
            }
            return(domains);
        }