how to list users to the active directory?

can i create session about other directory?? (no “system” directory)

What exactly would you like to do with the active directory? The IDirectorySession encapsulates all of the configured directory services.

However, you can search against a specific directory service:

String directoryServiceID = "";  // replace with the ID of your active directory
	IDirectorySession session = null;
	IDirectoryPagingCookie cookie = null;
	try {
		// create directory session
		IDirectorySystem ds = DirectorySystemFactory.getDirectorySystem();
		session = ds.createSession();
		// create initial paging cookie
		cookie = session.createPagingCookie(directoryServiceID);
		// create directory search query - search for userID and return 1 result row
		DirectorySearchQuery query = new DirectorySearchQuery(userID, 1, null);  
		List<IDirectoryPrincipal> list = session.searchDirectory(directoryServiceID, IDirectoryPrincipal.TYPE_USER, query, cookie);
		if( list.size() > 0 ) {
			IDirectoryPrincipal dirUser = list.get(0);
			// TODO: do stuff with the principal - can cast it to IDirectoryUser
	finally {
		// cleanup
		if( session != null ) {
			if( cookie != null ) {


now i need list all users of the Active Directory

the PageSize is 2000 but only list 834. Why?

I need to use the method “pageForward()” ? to implement this?

Hi Guido,

as the 834 entries returned do fit in one page of max 2000 entries, there are no more pages available for which pageForward could be used.

You can try to adjust the pagesize or implement a check how many entries/pages have been returned.
Only for the case that there are more than one page you can the step through the pages otherwise you are done with whatever you plan to do with these users at the end of the first (and only) page.