System.DirectoryServices.AccountManagement functions fail to probe some machines (but not others)

Posted by JCCyC on Stack Overflow See other posts from Stack Overflow or by JCCyC
Published on 2010-05-21T17:36:46Z Indexed on 2010/05/21 17:40 UTC
Read the original article Hit count: 800

Filed under:
|

Both the working and failing targets are machines in the same domain. Code is down below. When I use it against some machines in my domain, I get a System.DirectoryServices.AccountManagement.PrincipalOperationException with a message: "While trying to retrieve the authorization groups, an error (1332) occurred." The error is thrown by GetAuthorizationGroups().

Note: The username I use to connect is a local admin to the machine in both cases.

    PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machineName, domainname + "\\" + adminusername, pass);
    List<Principal> retList = new List<Principal>();

    using (var user = UserPrincipal.FindByIdentity(ctx, probedusername))
    {
        if (user != null)
        {
            PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();
            foreach (Principal group in groups)
            {
                retList.Add(group);
            }
        }
    }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about probing