tags:

views:

103

answers:

0

I find that NetLocalGroupGetMembers is many times faster than using the AccountManagement name space. How can I optimally rewrite the following code to approach the speed of accountmaangement (assume recursive = false)? Or is there a better approach?

   public List<Principal> GetMembersOfGroup(string groupName, bool recursive)
    {
        List<string> res = new List<string>();
        using (GroupPrincipal group = GroupPrincipal.FindByIdentity(this.MyPrincipalContext, IdentityType.Name, groupName))
        {
            return group.GetMembers(recursive).ToList<Principal>();
        }
    }

Running that code on my machine takes about 6-8 seconds (albeit running in debugger), whereas NetLocalGroupGetMembers is < 1s.

I would like to use the speed of NetLocalGroupGetMembers but I would also like to get additional information such as DisplayName (can I do that with NetLocalGroupGetMembers?)

My goal is to bind a view to the list of members in a local group, but i would like to show the users by display/full name, not NT name.

(just to clarify, I'm browsing groups in LOCAL machine, not ADSI)