Export (0) Print
Expand All

Managing Dependencies on the ADAM Service

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2

When you write applications as Windows services that use ADAM as a dedicated LDAP directory service, you must ensure that the required ADAM instance is started before the application service is started. The Windows Service Control Manager (SCM) maintains a database of services in the Windows registry at:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

Each service has a key at this location. SCM provides a mechanism for controlling the start order of services, using a predefined registry key value, DependOnService. DependOnService contains a list of the other services that should start before the current service. Your application’s setup program can add the name of the required ADAM instance to its DependOnService registry location to force Windows to start the ADAM instance before starting the application service. By convention, the name of the ADAM instance service to add to the DependOnService is ADAM_instancename, where instancename represents the name of the ADAM instance that you provide through the Active Directory Application Mode Setup Wizard or through a text answer file.

As an alternative, developers who use the Microsoft .NET Framework class library can use the ServiceProcessInstaller class to establish the appropriate dependency. The installation utility InstallUtil.exe uses ServiceProcessInstaller to write registry values that are associated with the services that you want to install. The following code demonstrates an application that is written as a service establishing a dependency on an ADAM instance called MyAdamDirectory:

private void InitializeComponent()
{
this.serviceProcessInstaller1 = new 
System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
// 
// serviceProcessInstaller1
// 
this.serviceProcessInstaller1.Account = 
System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
// 
// serviceInstaller1
// 
this.serviceInstaller1.ServiceName = "ApplicationServiceName";
this.serviceInstaller1.ServicesDependedOn = 
new string[] {"ADAM_MyAdamDirectory"};
// 
// ProjectInstaller
// 
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});

}

Windows applications and services can query the state of the ADAM service instance at any time and issue commands to manipulate its state. The following code checks to see if the ADAM instance is stopped. If the ADAM service is stopped, it will be started.

System.ServiceProcess.ServiceController sc2 = new 
System.ServiceProcess.ServiceController("ADAM_Instance3");
if (sc2.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped)){
sc2.Start();
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft