enumerate local/domain members from local group

Discussion in 'ASP .Net Security' started by soler, May 25, 2006.

  1. soler

    soler Guest

    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
     
    soler, May 25, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shiv
    Replies:
    3
    Views:
    6,788
    S. Justin Gengo
    Dec 3, 2003
  2. Steve Oswald via DotNetMonster.com

    Enumerate members of a group in vb.net codebehind pages...

    Steve Oswald via DotNetMonster.com, Jan 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,564
    Kevin Spencer
    Jan 14, 2005
  3. andres
    Replies:
    1
    Views:
    5,275
    dgoyani
    Oct 23, 2007
  4. Akaketwa
    Replies:
    1
    Views:
    4,904
    impaler
    Sep 22, 2006
  5. Chad Dressler
    Replies:
    0
    Views:
    644
    Chad Dressler
    Dec 30, 2006
Loading...

Share This Page