Enumerating Installed Software Features

Microsoft® Windows® 2000 Scripting Guide

Because much of the software developed today allows the user to choose which features to install, enumerating only the software packages might not provide a complete picture of the software installed on that computer. To obtain more detailed information about the software installed on a computer, you might need to enumerate the installed features of each software package, including such things as a dictionary, clip art, and design templates.

You can retrieve a list of software features by using the Win32_SoftwareFeature class. Some of the primary properties of this class are listed in Table 8.15.

Table 8.15 Win32_SoftwareFeature Properties

Property

Description

Accesses

Number of times the software feature has been used.

Attributes

Feature execution option. Values include:

0 - Install components locally if possible.

1 - Install components to run from the source CD/server if possible.

2 - Follow the remote execution option of the parent feature.

Caption

Short textual description of the object.

Description

Textual description of the object. In practice, this will often return the same value as Caption.

IdentifyingNumber

Product identification, such as a serial number.

InstallDate

Date the feature was installed.

InstallState

Installed state of the product. Values include:

6 - Bad configuration

-2 - Invalid argument

-1 - Unknown package

1 - Advertised

2 - Absent

3 - Local

4 - Source

LastUse

Date and time the software feature was last used. If the application has never been used, this date will typically be January 1, 1980.

Name

Label by which the object is known.

ProductName

Commonly used product name.

Vendor

Name of the product's supplier.

Version

Product version information.

Scripting Steps

Listing 8.13 contains a script that enumerates the software features installed on a computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.

  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."

  3. Use the ExecQuery method to query the Win32_SoftwareFeature class.

    This query returns a collection consisting of all the software features for all the software products installed on the computer.

  4. For each feature in the collection, echo the appropriate properties.

Listing 8.13 Enumerating Installed Software Features

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFeatures = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_SoftwareFeature")
For each objFeature in colFeatures
 Wscript.Echo "Accesses: " & objFeature.Accesses
 Wscript.Echo "Attributes: " & objFeature.Attributes
 Wscript.Echo "Caption: " & objFeature.Caption
 Wscript.Echo "Description: " & objFeature.Description
 Wscript.Echo "Identifying Number: " & objFeature.IdentifyingNumber
 Wscript.Echo "Install Date: " & objFeature.InstallDate
 Wscript.Echo "Install State: " & objFeature.InstallState
 Wscript.Echo "Last Use: " & objFeature.LastUse
 Wscript.Echo "Name: " & objFeature.Name
 Wscript.Echo "Product Name: " & objFeature.ProductName
 Wscript.Echo "Vendor: " & objFeature.Vendor
 Wscript.Echo "Version: " & objFeature.Version
Next