get local and domain members from local group?

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

  1. andres

    andres Guest

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

  2. andres

    dgoyani

    Joined:
    Jul 26, 2007
    Messages:
    4
    Andres,
    Use LDAP path to retrieve domain usernames and group details. WinNT only retrieves local users/groups detail.

    Thanks,
    dgoyani
    http://dgoyani.blogspot.com/
     
    dgoyani, Oct 23, 2007
    #2
    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. =?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:
    636
    David Jessee
    Jan 25, 2005
  2. =?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:
    609
    =?Utf-8?B?Um9ja3k=?=
    Dec 30, 2005
  3. Akaketwa
    Replies:
    1
    Views:
    4,899
    impaler
    Sep 22, 2006
  4. Chad Dressler
    Replies:
    0
    Views:
    642
    Chad Dressler
    Dec 30, 2006
  5. soler
    Replies:
    0
    Views:
    226
    soler
    May 25, 2006
Loading...

Share This Page