Re: NetQueryDisplayInformation Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 12/29/04


Date: Wed, 29 Dec 2004 11:57:03 +0100


"Sam Evans" <wintrmte@gmail.com> wrote in message
news:U-qdnUyk-_31m0_cRVn-1g@giganews.com...
> Thank you for the reply, Willy.
>
> From reading the ADSI information it seems like it is geared towards
> enumerating information from Active Directory its self rather than having
> anything to do with a local machine.
>
> I'm trying to enumerate members of a group from a local machine (i.e.,
> connecting to the local machine and finding out who the members are of its
> local Administrators group).
>
> Would the ADSI still work for me in this situation?

ADSI and the ADSI wrappers in System.DirectoryServices are not only
targetting LDAP servers (AD) but also the local security administrative
service & SAM database. This is done through two different client providers,
one is the LDAP provider the other is the WinNT provider. The first can (and
should ) be used when connecting to the AD (or any LDAP v2 compliant)
directory service. The latter can be used to connect to a NT4 domain (and AD
domain, but this is not advisable) or local server.

Here's a sample that enumerates a local alias:

 private static void ListMembersInGroup2(string GroupName)
{
// Connect to a local server using the WinNT provider interface
  using(DirectoryEntry groupEntry = new
DirectoryEntry("WinNT://YourMachineName/" + GroupName + ",group"))
  {
   object members = groupEntry.Invoke("Members");
   foreach( object member in (IEnumerable) members)
   {
    DirectoryEntry x = new DirectoryEntry(member);
    Console.WriteLine("ADsPath "+ x.Path + " Name: " + x.Name);
   }
  }
 }

 public static void Main()
{
  ListMembersInGroup("Users"); // enum 'users' alias
 }

And here a more elaborated sample. This one uses COM interop to access the
native ds classes from activeds.dll, so you need to add a reference to
activeds.tlb (in system32) and you have to add a using clause to import that
namespace.

 private static void ListMembersInGroup2(string GroupName)
{
  IADsMembers MembersCollection = null;
  using(DirectoryEntry groupEntry = new DirectoryEntry("WinNT://acer1/" +
GroupName + ",group"))
  {
   // invoke native method "members"
   MembersCollection = groupEntry.Invoke("Members") as IADsMembers;
   object[] filter = {"User"}; // return only User objects
   MembersCollection.Filter = filter;
   foreach (IADsUser member in MembersCollection) {
    DirectoryEntry x = new DirectoryEntry(member);
    foreach(string s in x.Properties.PropertyNames)
    {
     Console.WriteLine("{0} \t\t {1}", s, x.Properties[s].Value);
    }
   }
}

Willy.



Relevant Pages

  • Re: question(s) re: win32::ole and active-directory interaction
    ... I have attached a module I wrote to simplify ADSI queries. ... our $ADSILastErr = ''; ... =head1 VERSION ... Gets all members of a group, ...
    (comp.lang.perl.modules)
  • Re: question(s) re: win32::ole and active-directory interaction
    ... You should be able to get the basics of ADSI over Win32::OLE by looking at the code. ... our $ADSILastErr = ''; ... =head1 VERSION ... Gets all members of a group, ...
    (comp.lang.perl.modules)
  • Re: NetQueryDisplayInformation Question
    ... From reading the ADSI information it seems like it is geared towards ... enumerating information from Active Directory its self rather than ... I'm trying to enumerate members of a group from a local machine (i.e., ... Would the ADSI still work for me in this situation? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Enumerating Domain Members
    ... >> What I need is to enumerate the domain members, ... Since I have to execute these functions on the ... >> automatically be enumerating ... >>>SAM the way member servers do. ...
    (microsoft.public.security)
  • Re: Strange ADAM behavior
    ... > groups that have only a few members that are displaying the same behavior. ... > software and adsi edit. ... > something to do with the replication. ... >>> We have an adam instance that is replicated to another adam. ...
    (microsoft.public.windows.server.active_directory)