Export (0) Print
Expand All

Enumerating Installed Software

Microsoft® Windows® 2000 Scripting Guide

Knowing the software packages that have been installed on a computer is useful for many reasons. Among other things, this knowledge helps you:

  • Gain insight into what the computer is used for. A computer that does not have a word processor installed is probably not used for writing memos or other documents.

  • Ensuring that only licensed software, and only approved software, is in use in your organization. If your organization has decided to standardize on Microsoft Excel, it is very useful, for both support and legal reasons, to know whether anyone has installed a different spreadsheet program on a computer.

  • Tracking the progress of software deployment projects (for example, the number of people who have installed this new application and the number of people who have not).

  • Planning for future software needs.

These activities cannot be carried out using Group Policy because the Software Installation and Maintenance component does not provide information on the software installed on a computer; it only makes that software available for installation. For example, although the Software Installation and Maintenance component can publish a software package, it provides no way to track which users install that package. This makes it difficult to analyze actual software use or to make projections for future software needs.

The WMI Win32_Product class enables you to enumerate the software installed on a computer, provided the software was installed by using the Windows Installer. Selected properties available through the Win32_Product class are shown in Table 8.14.

Table 8.14 Win32_Product Properties

Property

Description

Caption

Short description of the object.

Description

Object description.

IdentifyingNumber

Product identification, such as a serial number on software.

InstallLocation

Location of the installed product.

InstallState

Installed state of the product. Values include:

-6 -Bad configuration

-2 - Invalid argument

-1 - Unknown package

1 - Advertised

2 - Absent

6 - Installed

Name

Commonly used product name.

PackageCache

Location of the locally cached package for this product.

SKUNumber

Product SKU (stock-keeping unit) information.

Vendor

Name of the product's supplier.

Version

Product version information.

Scripting Steps

Listing 8.12 contains a script that enumerates the software installed on a computer and then saves the information to a text file. To carry out this task, the script must perform the following steps:

  1. Create an instance of the FileSystem Object.

    This object will be used to write the retrieved software information to a text file.

  2. Create the text file C:\Scripts\Software.tsv.

  3. Write the field headers to the text file in tab-separated-values format.

    The VBScript constant VbTab is used to insert a tab character between each field header. The tab-separated-values format is used because software property values sometimes contain commas. If they do, these extra commas can make it difficult to parse a text file saved in comma-separated-values format.

  4. Create a variable to specify the computer name.

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

  6. Use the ExecQuery method to query the Win32_Product class.

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

  7. For each software product installed on the computer, retrieve the property values for the application and write those values to the text file, separating each value using a tab character.

  8. Close the text file.

Listing 8.12 Enumerating Installed Software

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\scripts\software.tsv", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
 & "Version"
For Each objSoftware in colSoftware
 objTextFile.WriteLine objSoftware.Caption & vbtab & _
 objSoftware.Description & vbtab & _
 objSoftware.IdentifyingNumber & vbtab & _
 objSoftware.InstallLocation & vbtab & _
 objSoftware.InstallState & vbtab & _
 objSoftware.Name & vbtab & _
 objSoftware.PackageCache & vbtab & _
 objSoftware.SKUNumber & vbtab & _
 objSoftware.Vendor & vbtab & _
 objSoftware.Version
Next
objTextFile.Close

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft