ORIGINALLY POSTED BY TALEN HERE

NOT ALL THE CODE MAY BE IN THIS POST…PLEASE FOLLOW THE LINK TO THE ORIGINAL THREAD

I needed a way to identify which workstations on the network had Microsoft Office installed from an Administrative Installation point as opposed to those that had Office installed from CD. It turns out there is a registry key value that points to the source path that the Microsoft Installer used to install the application, so I wrote the following script to take advantage of that:

Code: Select all
'   NAME   :   enumLastUsedSource.VBS
'   AUTHOR:   Talen
'   DATE   :   2007.04.25
'   COMMENT:   This script will read and enumerate the LastUsedSource value of all
'      subkeys in the HKEY_CLASSES_ROOT\Installer\Products registry key. The
'      LastUsedSource value is in the \SourceList subkey for every application
'      that was installed using the Microsoft Installer. In a nutshell, it will
'      reveal where a particular application was installed from. This script is
'      useful in determining which applications were installed from the network.
'      The script enumerates the values and inserts them into a database file
'      that can be local or on an available network share. It also creates a text
'      file named lastUsedSourceCheck.TXT on the root of the machine. If it finds
'      this file on subsequent executions the script will terminate.
'###############################################################################
Dim arrSubKeys
Dim objFSO, objShell, objFile, objReg, objConn
Dim strComputer, strLUSCheck, strKeyPath, strNValue01, strNValue02
Dim strWorkstationName, strDBPath, strSubKey, strKeyPath02, strRetValue01
Dim strRetValue02, strRetValNew02, strSQL

Const HKCR = &H80000000 'HKEY_CLASSES_ROOT

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")

strComputer = "."
strLUSCheck = "C:\lastUsedSourceCheck.TXT"
strKeyPath = "Installer\Products"
strNValue01 = "PackageName"
strNValue02 = "LastUsedSource"
strWorkstationName = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

If Not objFSO.FileExists(strLUSCheck) Then
Set objFile = objFSO.CreateTextFile(strLUSCheck)
objFile.Close

Set objReg = GetObject("winmgmts:\\" & strComputer & _
"\root\default:StdRegProv")

objReg.EnumKey HKCR, strKeyPath, arrSubKeys

Set objConn = CreateObject("ADODB.Connection")
strDBPath = "\\Server\Share\databaseFileName.MDB"
objConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & _
strDBPath & ";"

For Each strSubKey In arrSubKeys
strKeyPath02 = "Installer\Products\" & strSubKey & "\SourceList"
objReg.GetStringValue HKCR, strKeyPath02, strNValue01, strRetValue01
objReg.GetStringValue HKCR, strKeyPath02, strNValue02, strRetValue02
strRetValNew02 = Mid(strRetValue02, 5)
strSQL = "INSERT INTO installedSoftware ([Workstation],[Package]," & _
"[SourcePath]) VALUES ('" & strWorkstationName & "','" & _
strRetValue01 & "','" & strRetValNew02 & "')"
objConn.Execute(strSQL)
Next
objConn.Close
End If

In my particular situation an put the entire script into a subroutine and added it to our domain login script, but it could certainly be executed various ways. It doesn’t need to write to a database either (although if you’re executing it from a login script it’s highly advised), it could write to a text file quite easily (the code would be simpler, in fact).

Enjoy.

By admin

Former Freehand Freelance Graphic Illustrator... been online since 2004 ( late starter ), blogging since 2005, presently writing a suspense-thriller e-book that began as a screenplay.

Leave a Reply

Your email address will not be published. Required fields are marked *