Platform SDK: Active Directory, ADSI, and Directory Services

Example Code for Recalculating the Hierarchy in the Exchange Directory Service

The following example code uses C++ to issue a hierarchy recalculation in the Exchange directory service. This example can easily be converted to Visual Basic using declarations to access the Win32 functions in advapi32.dll.

[C++]

#include <windows.h>

#define DS_SERVICE_CONTROL_RECALC_HIERARCHY ((DWORD) 129)

int main(int argc, char* argv[])
{
    SERVICE_STATUS SrvStat;
    SC_HANDLE hSCM;
    SC_HANDLE hService;

    hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
    hService = OpenService(hSCM, 
                "MSExchangeDS", 
                SERVICE_USER_DEFINED_CONTROL);

    ControlService(hService,
            DS_SERVICE_CONTROL_RECALC_HIERARCHY, 
            &SrvStat);

    if(hSCM != NULL)
        CloseServiceHandle(hSCM);
    if(hService != NULL)
        CloseServiceHandle(hService);

    return 0;
}

Note: This example is specific to Exchange Server version 5.5 and below, and is not upwardly compatible with Exchange 6.0. Management and access of Exchange 6.0 Servers should be made through the CDO Exchange Management interfaces instead.