Get a list of members of a WinNT group

后端 未结 3 535
日久生厌
日久生厌 2020-12-06 00:21

There are a couple of questions similar to this on stack overflow but not quite the same.

I want to open, or create, a local group on a win xp computer and add membe

3条回答
  •  粉色の甜心
    2020-12-06 00:53

    Microsoft .NET Framework provides a standard library for working with Active Directory: System.DirectoryServices namespace in the System.DirectoryServices.dll.

    Microsoft recommends using two main classes from the System.DirectoryServices namespace: DirectoryEntry and DirectorySearcher. In most cases, it is enough to use DirectorySearcher class only.

    UPDATE: I tested it on my machine - it works. But maybe I've misunderstood your question.

    Here is an example from an excellent CodeProject article:

    Get a list of users belonging to a particular AD group

    using System.DirectoryServices;
    
    ArrayList GetADGroupUsers(string groupName)
    {    
       SearchResult result;
       DirectorySearcher search = new DirectorySearcher();
       search.Filter = String.Format("(cn={0})", groupName);
       search.PropertiesToLoad.Add("member");
       result = search.FindOne();
    
       ArrayList userNames = new ArrayList();
       if (result != null)
       {
           for (int counter = 0; counter < 
              result.Properties["member"].Count; counter++)
           {
               string user = (string)result.Properties["member"][counter];
                   userNames.Add(user);
           }
       }
       return userNames;
    }
    

提交回复
热议问题