Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > enumerate local/domain members from local group

Reply
Thread Tools

enumerate local/domain members from local group

 
 
soler
Guest
Posts: n/a
 
      05-25-2006
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);
}



--
soler
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get local and domain members from local group? andres ASP .Net 1 10-23-2007 08:46 AM
how to create a group in LDAP server and add members to a particular group using JNDI? Akaketwa Java 1 09-22-2006 10:39 AM
Enumerate members of a group in vb.net codebehind pages... Steve Oswald via DotNetMonster.com ASP .Net 2 01-14-2005 06:00 PM
enumerate Users in Activedirectory group shiv ASP .Net 3 12-03-2003 08:55 PM
Enumerate Local Variable Scope Chris Hohmann ASP General 2 07-23-2003 05:52 PM



Advertisments