How to list Windows users and groups in ASP.NET?

后端 未结 2 571
我在风中等你
我在风中等你 2020-12-11 08:32

I have a ASP.NET Website project and I need to list all the users and their groups on my Windows system. I have set the identity impersonation to true and provided the usern

2条回答
  •  没有蜡笔的小新
    2020-12-11 08:35

    You probably want to start with the DirectoryEntry and Active Directory support in .net.

    Here's a good resource: http://www.codeproject.com/KB/system/everythingInAD.aspx

    Local access is similar, even if you're not in a domain:

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

提交回复
热议问题