Link

While struggling with creating some scripted uninstalls a while ago, I imagined that this information must be located somewhere in the registry as the Control Pannel Add/Remove programs needs to know how to accomplish this task somehowÂ… After searching a while through the registry I discovered what I was looking

for within the Registry Key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall; but it always took some fishing to find the uninstall string as the subkey names are often the MSI GUID not some easily identifiable

product name. I wrote the following Visual Basic Script, Inventory.vbs, to capture this registry information into a tab delimited text file easily viewed with a spreadsheet program for easily analysis.

Try out Inventory.vbs on a few workstations by just running the program to see what kind of information it will give you, double clicking Inventory.vbs in Windows Explorer is just fine to run the program as it does not expect any command line parameters. You should find a text file created in the current directory and depending on how you executed Install.vbs this should normally be the same directory that Install.vbs is located in.

This program can also be useful in collecting a software inventory for all of your workstations to include uninstall strings for all of the software on your network, potentially very useful if you have unwanted software on your network that needs to be uninstalled. First determine what network directory you would want the inventory information collected, and for the purpose of this example, create a subdirectory called “Inventory” and one called “Script”. Place the Inventory.vbs script in the Script subdirectory. Update Inventory.bat with the UNC location where the inventory is to be collected. Have all of your workstations execute Inventory.bat through whatever means you would do this in your environment, for me I do this with

an Altiris Deployment Server job. After data collection is complete, the collection can easily be compiled into a single text file from the command prompt with something like “copy inventory\* composite.txt” for easy sorting and analysis in spreadsheet program such as Microsoft Excel.

*****************

* Inventory.vbs *

*****************

Set objShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

strRegIdentityCodes = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

strRegComputerName = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"

strComputerName = objShell.RegRead(strRegComputerName)

Const HKLM = &H80000002

Const APPEND = 8

strFileOut = strComputerName & " Inventory.txt"

If objFSO.FileExists(strFileOut) Then

Set objFileOut = objFSO.OpenTextFile(strFileOut, APPEND)

objFileOut.WriteLine("")

Else

Set objFileOut = objFSO.CreateTextFile(strFileOut)

End If

objFileOut.WriteLine("Inventory for " & strComputerName & " at " & Now)

objFileOut.WriteLine("Computer Name" & vbTab & "Identity Code" & vbTab & "Display Name" & vbTab & _

"Display Version" & vbTab & "Install Date" & vbTab & "Uninstall String" & vbTab & _

"Quiet Uninstall String")

objReg.EnumKey HKLM, strRegIdentityCodes, arrIdentityCode

On Error Resume Next

For Each strIdentityCode in arrIdentityCode

strRegIdentityInfo = "HKLM\" & strRegIdentityCodes & "\" & strIdentityCode & "\"

strDisplayName = objShell.RegRead(strRegIdentityInfo & "DisplayName")

strDisplayVersion = objShell.RegRead(strRegIdentityInfo & "DisplayVersion")

strInstallDate = objShell.RegRead(strRegIdentityInfo & "InstallDate")

strUninstallString = objShell.RegRead(strRegIdentityInfo & "UninstallString")

strQuietUninstallString = objShell.RegRead(strRegIdentityInfo & "QuietUninstallString")

objFileOut.WriteLine(strComputerName & vbTab & strIdentityCode & vbTab & strDisplayName & vbTab & _

strDisplayVersion & vbTab & strInstallDate & vbTab & strUninstallString & vbTab & _

strQuietUninstallString)

strDisplayName = ""

strDisplayVersion =""

strInstallDate = ""

strUninstallString = ""

strQuietUninstallString = ""

Next

objFileOut.Close

*****************

* Inventory.bat *

*****************

@echo off

Rem Inventory from registry Add & Remove Programs

PushD \\(Server)\(Share)\(Path)\Inventory

CScript ..\Script\Inventory.vbs

PopD

To download the script, please see its listing in the Admin Script Editor Script Library