get local and domain members from local group?

A

andres

Can anyone suggest how to get the local and domain members from a local
group. The C# code is running from an ASP.NET 2.0 webpage.
The following code only returns the local members and not the domain
members as well.

//Start of Code

public string[] GetLocalGroups(string strComputer, string strUser,
string strPswd)
{
DirectoryEntry oComputer;
try
{
if (strUser == "" && strPswd == "")
oComputer = new DirectoryEntry("WinNT://" + strComputer);
else
oComputer = new DirectoryEntry("WinNT://" + strComputer,
strUser, strPswd);
}
catch (Exception)
{
return null;
}

string strOut = "";

DirectoryEntries ds = oComputer.Children;
foreach (DirectoryEntry group in ds)
{
if (group.SchemaClassName.Equals("Group"))
{
if (strOut != "")
strOut += ";";
//strOut += child.Properties["Name"].Value + "\t" +
child.Properties["Description"].Value;
strOut += group.Properties["Name"].Value;

DirectoryEntry oGroup;
try
{
oGroup = new DirectoryEntry("WinNT://" +
strComputer + "/" + group.Properties["Name"].Value, strUser, strPswd,
AuthenticationTypes.Secure);
}
catch (Exception)
{
return null;
}

foreach (object obj in
(IEnumerable)oGroup.Invoke("members"))
{
using (DirectoryEntry user = new DirectoryEntry(obj))
{
strOut += ";\t" + user.Name;

}
}
}
}

string[] arrGroups = null;

if (strOut != "")
{
arrGroups = strOut.Split(';');
}
return (arrGroups);
}

// End Of Code

Thanks
Andres
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top