Can you find an Active Directory User's Primary Group in C#?

前端 未结 3 1606
不思量自难忘°
不思量自难忘° 2020-12-10 08:06

I am working on an application that manages user accounts in Active Directory. I am using the System.DirectoryServices.AccountManagement namespace whereever possible, but I

3条回答
  •  余生分开走
    2020-12-10 08:37

    The RID of the user's primary group is stored in the 'primaryGroupID' attribute on the user object. You'd have to get the DirectoryEntry for the given user (or user other API's) in order to retrieve this value. After getting that value, you'd have to translate it into a SID for the primary group, and then get the group from that.

    There is a KB article that has more detail on this, as well as VB code with how to find the primary group, here: http://support.microsoft.com/kb/297951

提交回复
热议问题