EvoCorp Home    Delphi::Advance

 

 

   

 

Determining the Groups a User Belongs to on an NT Based Machine.

Before I start, I realize that you're probably wondering why I've got code here for enumerating user groups on an NT domain, as either finding or writing this code yourself is a relatively easy task. The answer is simple: it's easily accessible code and if you need it, here it is.

If you require a more complex interface for accessing and/or modifying user groups, Delphi-JEDI's JCL contains a couple of units (JclLANMan and LM) for better utilization of Microsoft's NET API functions. Similar

This code contains the following functions:

  GetDomainController  

Returns the domain controller trusted by the current machine.
 

  GetPrimaryDomainControllers   Returns a complete list of primary domain controllers for the current user's domain login. Therefore a user MUST be logged onto a domain controller (and NOT the local machine) for this call to work.
 
  GetUserGroups(Groups: TStrings)   Returns the complete list of groups found for the current user within the primary domain controller as defined by a call to GetDomainController.
 
  GetUserGroups(const UserName: WideString; Groups: TStrings)   Returns the complete list of groups found for user "UserName" within the primary domain controller as defined by a call to GetDomainController.
 
  GetUserGroups(const PDC, UserName: WideString; Groups: TStrings)   Returns the complete list of groups found for user "UserName" as defined on the primary domain controller machine "PDC".
 
  IsUserInGroup(const GroupName: WideString): Boolean   Identifies whether the current user within the first primary domain controller as defined by a call to GetPrimaryDomainControllers exists within group "GroupName".
 
  IsUserInGroup(const UserName, GroupName: WideString): Boolean   Identifies whether the user "UserName" within the first primary domain controller as defined by a call to GetPrimaryDomainControllers exists within group "GroupName".
 
  IsUserInGroup(const PDC, UserName, GroupName: WideString): Boolean   Identifies whether the user "UserName" within primary domain controller "PDC" exists within group "GroupName".

Requirements

  • This code will only work on NT based systems
    (Windows NT Client and Server, Windows 2000, Windows XP and Windows 2003)
  • Delphi 6

Download Code

UserGroups.pas can be downloaded here.
 

Microsoft Internet Explorer is a registered trademark of Microsoft Corporation.