如何使用C#代码在Windows XP PC中查找所有域的列表 [英] How to find list of all domains in windows xp pc using c# code

查看:102
本文介绍了如何使用C#代码在Windows XP PC中查找所有域的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想使用c#
在Windows XP中找到所有域的列表 因为在我的c#应用程序中为登录用户的域环境提供了安全性

我尝试使用此代码,但我只会找到管理员用户.

但是我想使用C#在Windows XP PC中维护所有域和用户,任何人都可以通过最好的示例对此进行很好的建议.

这是我的代码

hello every body

i want to find list of all domains in windows xp using c#
becuase of providing security under domain environment of the login users into my c# application

i tried on this code i will find only admin users.

but i want to maintain all domains and users in windows xp pc using c# any one give good sugisstions on this with best examples.

here is my code

DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName);
            // DirectoryEntry admGroup = localMachine.Children.Find("Guests", "group");
           // DirectoryEntry admGroup = localMachine.Children.Find("administrators", "group");
            DirectoryEntry admGroup = localMachine.Children.Find("users", "group");
            //DirectoryEntry admGroup = localMachine.Children.Find("TestUser1", "group");
            object members = admGroup.Invoke("members", null);
            foreach (object groupMember in (IEnumerable)members)
            {
                DirectoryEntry member = new DirectoryEntry(groupMember);
                listBox1.Items.Add(member.Name);
            }

推荐答案

添加对System.DirectoryServices.dll
的引用
Add a reference to System.DirectoryServices.dll

using (var forest = Forest.GetCurrentForest())
{
    foreach (Domain domain in forest.Domains)
    {
        Debug.WriteLine(domain.Name);
        domain.Dispose();
    }
}





从这里摘录:
> http://stackoverflow.com/questions/2596419/how-to-获取所有域列表 [ ^ ]





Extracted from here :
http://stackoverflow.com/questions/2596419/how-to-get-a-list-of-all-domains[^]


这篇关于如何使用C#代码在Windows XP PC中查找所有域的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆