Using VB.NET, call the "Members" native ADSI method, VB has the advantage of better
late binding support over C#:
Imports System.DirectoryServices
Imports System
Module Module1
Sub Main()
' using late binding
Dim MembersCollection as Object
Try
'Get the entries of the Users group 'Group' collection
Dim Group As new DirectoryEntry ("WinNT://servername/Users,group")
MembersCollection = Group.Invoke("Members")
Dim filter As System.Object() = {"user"}
MembersCollection.Filter = filter
' Iterate over the User objects (IADsUser) using late binding
Dim user as Object
for each user in MembersCollection
Console.WriteLine("ADsPath "+ user.ADsPath + " Name: " + user.Name )
next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Module
' Compile from the command line using:
'vbc /r:system.directoryservices.dll,System.dll groupmembers.vb
Using C#, you have add a reference to the "activeds.tlb" and call the Native ADSI
method "Members".
using activeds;
....
IADsMembers MembersCollection = null;
try {
DirectoryEntry groupEntry = new
DirectoryEntry("WinNT://ServerName/Administrators,Group");
PropertyCollection pcoll = groupEntry.Properties;
MembersCollection = groupEntry.Invoke("Members") as IADsMembers;
object[] filter = {"user"};
MembersCollection.Filter = filter;
// enumerate members of collection object that supports the IADsMembers interface
// ADSI provider doesn't support count property
try {
foreach (IADsUser member in MembersCollection) {
Console.WriteLine("ADsPath "+ member.ADsPath + " Name: " + member.Name );
}
}
catch (COMException e) {
Console.WriteLine("Error: {0}",e.Message);
}
}
catch (COMException e) {
Console.WriteLine(e.Message);
}
....
....
Willy.
----- Original Message -----
From: "george antony" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 19, 2002 7:20 AM
Subject: [DOTNET] Retrieving user properties from a WinNT provider using .Net
> Hi guys ,
> I have a query here . We are developing an application
> which needs to find the users of a particular group in
> the WinNT Domain . I could get connected to the WinNT
> provider using the DirectoryEntry class. But I
> couldn't find any sample to retrieve the users of the
> object . I am confused as to how to treat a user
> object and a group object in .Net.
>
> We need it urgently to complete our project..
>
> Thanks for any help
> George
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.