Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I verify that ADAM is installed?

-- CW

SpacerHey, Scripting Guy! AnswerScript Center

Hey, CW. Although former President Ronald Reagan is usually given credit for the phrase “Trust but verify,” we’ve always thought that sounded more like the sort of thing a system administrator would say: “Of course I trust you when you say you installed ADAM on that computer. I just need to verify that it was installed. That’s a whole different thing.”

So how can you verify that ADAM (Active Directory Application Mode) is installed on a computer? Here’s one way, a scripting solution that is also usually credited to former President Reagan:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name Like '%ADAM_%'")

If colServices.Count = 0 Then
    Wscript.Echo "ADAM is not installed."
Else
    For Each objService in colServices
        Wscript.Echo objService.Name & " -- " & objService.State
    Next
End If

This script relies on the fact that ADAM runs as a service: if the script uncovers an instance of the ADAM service then you know that ADAM is installed. Admittedly, there’s a catch here: each instance of ADAM runs as a separate service with a separate name. Fortunately, there’s also an easy way to determine whether any instance of ADAM is installed. And that’s exactly what we’re going to talk about next.

The script begins by connecting to the WMI service on the local computer; as usual, you can modify this script to work against a remote machine simply by assigning the computer name to the variable strComputer. We then encounter this line of code:

Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name Like '%ADAM_%'")

What we’re doing here is using the Like operator to return all services where the service name includes the characters ADAM_. When using WMI’s LIKE operator the two percentage signs stand for “anything.” That means our query reads, “Get me all the services that have the characters ADAM_ somewhere in the Name property. I don’t care what comes before or after the ADAM_; I just care that the string ADAM_ appears somewhere in the Name.”

Why do we do this? Well, as we noted, each instance of ADAM runs as a separate service; however, each service name will begin with the characters ADAM_. For example, if you have an instance of ADAM named Fabrikam the service name will be ADAM_Fabrikam; if you have an instance of ADAM named Contoso the service name will be ADAM_Contoso. We’ve constructed our query to ensure that either of those two instances - or any other services with the characters ADAM_ in the Name - will be returned as part of the services collection.

Note. Of course, you might be thinking, “Wait a second, Scripting Guys: isn’t the LIKE operator supported only on Windows XP and Windows Server 2003? What if I’m running ADAM on Windows 2000?” Well, you are correct: the LIKE operator is supported only on Windows XP and Windows Server 2003. However, that shouldn’t pose much of a problem here because ADAM itself is supported only on Windows XP and Windows Server 2003. Because you can’t run ADAM on Windows 2000 you don’t have to worry about whether ADAM is installed on a Windows 2000 machine; it isn’t. Granted, you will have to run this script on a Windows XP or Windows Server 2003 machine. But if you’re using ADAM we’re assuming you’ll be able to find one of those computers without too much trouble.

After retrieving the collection of services we run into this If Then Else block:

If colServices.Count = 0 Then
    Wscript.Echo "ADAM is not installed."
Else
    For Each objService in colServices
        Wscript.Echo objService.Name & " -- " & objService.State
    Next
End If

What we’re doing here is checking to see if the Count property of the returned collection is equal to 0. The Count tells us how many items are in the collection: if the Count is equal to 0 then there are no items in the collection. In turn, that means no instances of ADAM are installed on the computer and we echo back that very message.

If the Count is greater than 0 that means at least one instance of ADAM was found. In that case, we set up a simple For Each loop to loop through all the instances of ADAM and, for each one, report back the instance Name and State (that is running, stopped, paused, etc.).

That’s all you have to do; just run this script and - what’s that? What do you mean you don’t trust us? Oh, we see: you do trust us, you just want to verify that the script actually works. We understand: that’s a whole different thing. Give it a try and see what happens.