NetQueryDisplayInformation Question

  • Thread starter Thread starter Sam Evans
  • Start date Start date
S

Sam Evans

All:

I am very new to C#, but not OO languages in general. I am working on a
project where I need to enumerate the members of a local group on
workstations. I was reading through the MSDN database and found the
NetQueryDisplayInformation API call.

I realize I can use the netapi32.dll from within C# but am a bit clear
as to how I can go about reading the information presented back from the
execution.

Does anyone know of, or have any examples that use the
NetQueryDisplayInformation API call?

Thanks,
Sam
 
Forget about the NetXXX API's, most of their functionality is covered by the
FCL classes and COM interop.
Enumerating local security databases can be done using the
System.DirectoryServices namespace classes with the WinNT adsi provider.
Search msdn for samples.

Willy.
 
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?

Thanks,
Sam
 
Sam Evans said:
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.Value);
}
}
}

Willy.
 
Willy,

This is perfect. It sets me on the right course, and is *much* easier
to use than the netapi32.dll.

Thank you very much for your help!!

Willy Denoyette [MVP] wrote:
- SNIP -
 
Back
Top