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. Advertisements

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,936
    S. Justin Gengo
    Dec 3, 2003
  2. Marek

    Enumerate group from asp

    Marek, Nov 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    474
    Marek
    Nov 4, 2004
  3. 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,721
    Kevin Spencer
    Jan 14, 2005
  4. =?Utf-8?B?aG93YXJkIGRpZXJraW5n?=

    Authentication not mapping domain user to local windows group

    =?Utf-8?B?aG93YXJkIGRpZXJraW5n?=, Jan 24, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    713
    David Jessee
    Jan 25, 2005
  5. =?Utf-8?B?Um9ja3k=?=

    How to Add a domain user to a local user group

    =?Utf-8?B?Um9ja3k=?=, Dec 30, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    703
    =?Utf-8?B?Um9ja3k=?=
    Dec 30, 2005
  6. andres
    Replies:
    1
    Views:
    5,521
    dgoyani
    Oct 23, 2007
  7. Akaketwa
    Replies:
    1
    Views:
    6,037
    impaler
    Sep 22, 2006
  8. Chad Dressler
    Replies:
    0
    Views:
    764
    Chad Dressler
    Dec 30, 2006
Loading...