enumerate local/domain members from local group

S

soler

I need to get the members of a local group that contains local as well as
domain groups in it. The following code only returns the local members from a
group.
Anyone can suggest ideas?. I am running the code from a web page in asp.net
2.0, the reason why I use userID/Password to connect to remote server.

public string[] GetLocalGroupMembers(string strComputer, string strUser,
string strPswd)
{
DirectoryEntry oComputer;
try
{
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 += group.Properties["Name"].Value;

DirectoryEntry oGroup;
try
{
// get the group object
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"))
{
// save the member name
using (DirectoryEntry user = new DirectoryEntry(obj))
{
strOut += ";\t" + user.Name;
}
}
}
}

string[] arrGroups = null;

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

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