A Quick Software Inventory Script

Use a script to find out who’s installed what software.

Rather than digging through the file system looking for known file names or file version information, the quick and easy way to get that info is to enumerate the subkeys in the Uninstall subkey of the registry. That is, you’re basically retrieving a list of each subkey in that level of the registry structure. Once you have that info, you can dynamically build a list of what’s installed by looking for some common registry values describing the installed items. What you’ll end up with will look suspiciously like what you’d see if you brought up the Add/Remove Programs applet (that’s because the script here and the ARP work off of the same data).

While KiXtart and AutoIt are nice enough to provide nice enumeration functions for the registry, the Windows Script Host leaves us hanging in this regard. Luckilly, there is always more than one way to skin a cat and this time we’ll call on WMI to provide with some similar functionality. WMI uses hexadecimal values to identify what hive in the registry you’re looking into, so let’s start by setting a few constants (unchangeable variables) to make the script easier to read:

Const HKCR = &H80000000
Const HKCU = &H80000001
Const HKLM = &H80000002

Next, you’ll need to get a handle on the WMI registry provider, which you do like so:

Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_

I know, it looks ugly, but that’s what VBscript damands of us sometimes. Now, set the path you want to enumerate:

sUninstallPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”

And finally, you can now enumerate all the subkeys beneath this registry path in the HKEY_LOCAL_MACHINE hive and store them in a variable named aSubkeys:

oReg.EnumKey HKLM, sUninstallPath, aSubkeys

The aSubkeys variable is an array, so you’ll run through each value it has using a For/Each loop. The GetStringValue method of the WMI registry provider is used here to build the path in the registry to each subkey of the Uninstall subkey, and inside this key is where you collect the value of “DisplayName” in a variable named sAppName. Finally you echo each value:

On Error Resume Next
For Each sSubkey In aSubkeys
oReg.GetStringValue HKLM, sUninstallPath &”\” &_
sSubkey, “DisplayName”, sAppName
WScript.Echo sAppName

You’ll note I’ve added the statement, “On Error Resume Next” here — this is to ensure the script does not produce an error if it looks inside one of these subkeys and does not find a value named “DisplayName” (which does happen for some applications that don’t like to follow the rules).

Want to inventory a remote system? If you have admin access to read their registry remotely, you can replace the period in the line where oReg (which means local system) is set to the name of a remote system. Here’s an example where a computer named COMPUTERNAME is inventoried:

Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: