April 18th, 2007

How Can I Tell Which Version of QuickTime is Installed on a Computer?

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I tell whether or not QuickTime is installed on a computer, and, if so, which version is installed?

— IU

SpacerHey, Scripting Guy! AnswerScript Center

Hey, IU. You know, for some reason this column suddenly seems to have become a daily dancing column rather than a daily scripting column. After all, just yesterday we recapped the Scripting Son’s … dancing … exploits at his cousin’s wedding. And now, today, the Scripting Guy who writes this column was getting a cup of coffee when he noticed an ad for tango lessons. Learn how to tango, said the ad, and you’ll be able to go into “ … any major city and dance – no partner required!”

We have to admit that, at first, this sounded like a pretty good deal, and we were all ready to sign up. But then we realized something: the Scripting Guys apparently don’t even need tango lessons. Go into any major city and not find someone who’d be willing to dance with you? That’s not much of a problem for the Scripting Guys; we don’t really need lessons on how not to get people to do anything with us.

On top of that, we’re a bit skeptical about this whole tango thing. Throughout his entire life the Scripting Guy who writes this column has been told that it takes two to tango. And now they’re telling him that no partner is required, that apparently it only takes one to tango. We’ll believe it when we see it.

Although we hope we never see any of the Scripting Guys doing the tango.

No, not even Peter. In fact, especially not Peter.

On the other hand, what we would like to see is the same thing IU would like to see: a script that can tell you whether or not QuickTime is installed on a computer. You know, a script similar to this one:

strComputer = “.”

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

Set colItems = objWMIService.ExecQuery _ (“Select * From Win32_Product Where Name = ‘QuickTime'”)

If colItems.Count = 0 Then Wscript.Echo “QuickTime is not installed on this computer.” Else For Each objItem in colItems Wscript.Echo “QuickTime version: ” & objItem.Version Next End If

As you can see, determining whether or not QuickTime is installed on a computer is even easier than doing the tango. (Or so we assume, having never actually done the tango.) As you can see, we start out by connecting to the WMI service on the local computer. However, like most WMI scripts, we can also use this one to determine whether or not QuickTime has been installed on a remote machine. How do we do that? Simple; we just assign the name of the remote computer (e.g., atl-ws-01) to the variable strComputer:

strComputer = “atl-ws-01”

After making the connection we then use this line of code to retrieve a list of all the installed software that has a Name with the value QuickTime:

Set colItems = objWMIService.ExecQuery _
    (“Select * From Win32_Product Where Name = ‘QuickTime'”)

Like we said, this returns a collection consisting of every application installed on the computer that has the name QuickTime. Now, suppose we don’t actually have QuickTime installed. That’s fine; in that case we simply get back a collection consisting of 0 items. In turn, that means we can identify whether or not QuickTime is installed simply by checking the number of items in the returned collection, something we do by examining the value of the collection’s Count property:

If colItems.Count = 0 Then

If Count is equal to 0 that means that QuickTime is not installed; therefore we echo back a message to that effect:

Wscript.Echo “QuickTime is not installed on this computer.”

Logically enough, that also means that, if the Count is greater than 0, then QuickTime must be installed. In that case we set up a For Each loop to loop through all the items in the collection and, for each item, echo back the value of the Version property:

For Each objItem in colItems
    Wscript.Echo “QuickTime version: ” & objItem.Version
Next

That’s going to be a value similar to this:

7.1.5.120

And there you have it: with that you’ll get back the version of QuickTime installed on the computer, and everyone will be happy.

Well, except maybe those people running Windows Server 2003. By default the Win32_Product class isn’t installed on Windows 2003; unless you’ve gone ahead and added this class (which can be done through Add or Remove Programs) this script won’t do you any good. But everyone else will be happy.

Well, except maybe those people running Windows Vista. As it turns out, the Win32_Product class is installed by default on Windows Vista; it’s even been enhanced with some additional properties. However, there are some known problems with Win32_Product class on Windows Vista: sometimes it doesn’t work at all (returning an error) and sometimes it works, but a bit more slowly than you might expect (or like). For example, that little script that tells us whether or not QuickTime is installed might take a minute (or even more) to complete.

If it’s any consolation, we agree with you.

So is there another way to determine whether or not QuickTime is installed and, if so, which version is installed? As a matter of fact there are a couple of workarounds that we know of. For example, if you’re performing this check as part of a logon script you can use this little script instead:

On Error Resume Next

Set objQuickTime = CreateObject(“QuickTimeCheckObject.QuickTimeCheck.1”)

If Err <> 0 Then Wscript.Echo “QuickTime is not installed on this computer.” Else Wscript.Echo “QuickTime version: ” & Hex(objQuickTime.QuickTimeVersion) End If

Here we’re trying to create an instance of the QuickTime.QuickTimeCheck.1 object. If the object cannot be created that means that QuickTime is not installed, and we echo back a message to that effect. If the object can be created we then grab the value of the Version property, convert that to a hexadecimal number, and then echo back the result:

Wscript.Echo “QuickTime version: ” & Hex(objQuickTime.QuickTimeVersion)

Why do we need to convert the value to a hexadecimal number? Beats us; we just have to. That’s because the Version comes back as a value like 118849536; converting that to a hex value results in a version number of 7158000. Is that good? Yes; on our test machine we happen to be running QuickTime 7.1.5.

Note. Why does this come back, in effect, as 7.1.5.8000 and the version reported by Win32_Product come back as 7.1.5.120? We don’t know. But 7.1.5 is the official version number reported through the QuickTime UI so we aren’t going to worry about the discrepancy.

Unfortunately, though, we have a problem with this script, too: the QuickTime.QuickTimeCheck.1 object can’t be created remotely. (That’s why we included the stipulation about performing this check as part of a logon script.) If you need to perform this task remotely you can, instead, read the value from the registry:

HKEY_LOCAL_MACHINE = &H80000002

strComputer = “.”

Set objReg = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “Software\Apple Computer, Inc.\QuickTime” ValueName = “Version”

objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, dwValue

If IsNull(dwValue) Then Wscript.Echo “QuickTime is not installed.” Else Wscript.Echo “QuickTime version: ” & Hex(dwValue) End If

This script should work on any version of Windows. So then why didn’t we just show you this particular script in the first place? Well, in general, we’re hesitant about using scripts that read directly from the registry; after all, there’s no guarantee that the registry path will remain the same when the next version of QuickTime is released. For that matter, we can’t even guarantee that this script will work with previous versions of QuickTime. That’s why, whenever possible, it’s better to let a WMI class such as Win32_Product do all the work rather than try and retrieve these values from the registry. (Editor’s Note: Another reason? On the Scripting Editor’s computer, the UI and Win32_Product report a version of 7.0.3; the check of the QuickTime.QuickTimeCheck.1 object returns 7038000; the registry returns 7028000.) But, like they say, desperate times call for desperate measures. And, as in this case, sort of, kind of desperate times call for sort of, kind of desperate measures.

If that sounds like we’re trying to dance around the problem, well, to a certain extent we are. But at least that gives you an alternative approach just in case you run into problems with the Win32_Product class. And we promise that this is the only dancing you’ll ever see from the Scripting Guys, even when they attend TechEd 2007 this coming June. For one thing, the Scripting Guy who writes this column doesn’t dance, period. For another, after her near-tragic incident in San Diego, we’ve been discouraging Scripting Guy Jean Ross from doing things that are just too difficult for her. “Do your walking first,” we tell her, “and then chew your gum.” With any luck she’ll listen to us this time. (Editor’s Note: Could it be that the Scripting Guy who writes this column is looking out for the well-being of a fellow Scripting Guy? Don’t believe it; he’s really just concerned that Scripting Guy Jean Ross will embarrass him. Which is entirely possible – even likely.)

Author

0 comments

Discussion are closed.