Platform SDK: Active Directory, ADSI, and Directory Services

Polling for Changes Using USNChanged

The DirSync control is robust, efficient, and easy to use. But it has two significant limitations:

There's another way to get changes from Active Directory™ that avoids these limitations: uSNChanged querying. This alternative is not better than the DirSync control in all respects – it involves transmitting all attributes whenever any attribute changes, and it requires more work from the application writer to handle certain failure scenarios correctly. But it is the best way available to write certain change-tracking applications today.

Here's the technical background on the uSNChanged attribute:

With that background, it is easy to see the general outline of how to use uSNChanged to track changes in a subtree S. First perform a "full sync" of the subtree S. Suppose the largest uSNChanged seen on any object in S is U. Now periodically query for all objects in subtree S whose uSNChanged is greater than U. The query will return all objects that have changed since the full sync. Set U to the largest uSNChanged among these changed objects, and you are ready to poll again when the time comes.

The subtleties of implementing a USNChanged synchronization application are as follows:

For sample code that demonstrates the basics of a USNChanged synchronization application, see Example Code to Retrieve Changes Using USNChanged.