Using Visual Studio C#

The following steps describe how to call the Centrify Windows API when using Visual Studio 2010. Alternatively you can use the command line compilers that come in Microsoft .Net Framework SDK or the Visual Studio Express Edition. The example below is created using C#, however using vb.net is very similar.

Note that the .NET assemblies are not installed in the Global Assembly Cache, but they do have version numbers on them. This means that the calling applications are tied to using the same assembly versions they were compiled with. To avoid problems using the assemblies, you should install the assemblies and the applications that use the assemblies in the same directory.

  1. Verify that the computer you are using has Access Manager or the Centrify Windows API Runtime environment from the Centrify SDK installed.
  2. Verify that the computer you are using is a member of the Active Directory domain you want to work with.
  3. Log in as a domain user with permission to read the zone data for the zone you will be listing.

    If you can list the users in the zone using Access Manager with the credentials provided, you have the correct permissions. For information about configuring a user’s rights to read zone data, see the Planning and Deployment Guide.

  4. Start vs2010 and start a new project of type C# console application.

  5. Click Project > Add reference.

  6. Click the .NET tab, then click Browse.

  7. Navigate to the directory where Access Manager or the SDK is installed. For example, browse to the default location C:\Program Files\Centrify\.

  8. Select the following dynamic link libraries to add:

       centrifydc.api.dll
       interface.dll
       nismap.api.dll
       PropSheetHost.dll
       util.dll
  9. Add a reference to system.directory services. From the Project menu, select Add references. In the .NET tab scroll down to system.directoryservices.dll.

  10. Open the class file that contains the application’s Main function. By default, Visual Studio creates this file as class1.cs.
  11. Add the following code in the Main function, replacing the domain_name and the path to the zone with a domain controller and zone location appropriate for your environment:

       Centrify.DirectControl.API.Cims cims = new
       Centrify.DirectControl.API.Cims();
       Centrify.DirectControl.API.IZone zone =
       cims.GetZone("domain_name/zone_path/zone_name");
       foreach (Centrify.DirectControl.API.IUserUnixProfile user in zone.GetUserUnixProfiles())
       {  
         string name, uid;  
         if (zone.IsHierarchical &&
       !
       ((Centrify.DirectControl.API.CDC50.UserUnixProfile)user).IsNameDefined)
         {    
           name = "<Empty>"; 
         } 
         else  
         {    
           name = user.Name;  
         }  
         if (zone.IsHierarchical &&
       !
       ((Centrify.DirectControl.API.CDC50.UserUnixProfile)user).IsUidDefined)
         {    
           uid = "<Empty>";  
         }  
        else  
         {    
           uid = user.UID.ToString();  
         } 
         Console.WriteLine(name + " | " + uid);
       }

    For example if you are using the domain dc2k.seattle.test and want to list users in the “default” zone in its default container location:

      Centrify.DirectControl.API.IZone zone = 
      cims.GetZone("dc2k.seattle.test/program data/centrify/zones/default");
  12. Press F5 to compile and run the application.