Wednesday, December 30, 2009

List all installed software

This code is useful in documenting what is installed on a computer including Microsoft patches.  The original version I wrote formatted the output for a Wiki. The output is created in the same directory as the script, example: [mycomputer]-inventory.txt

Code – *.vbs

Option Explicit
Const HKLM = &H80000002 ' HKEY_LOCAL_MACHINE
Const APPEND = 8 ' Append to file
dim objShell
dim objFso
dim objReg
Set objShell = CreateObject("WScript.Shell")
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objReg = GetObject("WinMgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

dim strRegIdentityCodes
dim strRegComputerName ' registry path to machine name
dim strComputerName ' computer name
strRegIdentityCodes = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
strRegComputerName = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"
strComputerName = objShell.RegRead(strRegComputerName)

' Create file delete if it already exists
dim strFileOut
strFileOut = strComputerName & "-Inventory.txt"
If objFso.FileExists(strFileOut) Then
objFso.DeleteFile strFileOut, true
End If
dim objFileOut
Set objFileOut = objFSO.CreateTextFile(strFileOut)

dim arrIdentityCode
objReg.EnumKey HKLM, strRegIdentityCodes, arrIdentityCode
objFileOut.WriteLine("Computer Name: " & strComputerName)
objFileOut.WriteLine("Inventory of installed products taken on: " & Now)
objFileOut.WriteLine("")

On Error Resume Next
dim strIdentityCode
dim strRegIdentityInfo
dim strDisplayName
dim strDisplayVersion
For Each strIdentityCode in arrIdentityCode
strRegIdentityInfo = "HKLM\" & strRegIdentityCodes & "\" & strIdentityCode & "\"
strDisplayName = objShell.RegRead(strRegIdentityInfo & "DisplayName")
strDisplayVersion = objShell.RegRead(strRegIdentityInfo & "DisplayVersion")
if(strDisplayName <> "")then
objFileOut.WriteLine(strDisplayName)
objFileOut.WriteLine(chr(9) & strIdentityCode & ", " & strDisplayVersion )
end if
strDisplayName = ""
strDisplayVersion =""
Next

objFileOut.Close
objShell.Run "cmd /c C:\WINDOWS\pchealth\helpctr\binaries\helpctr.exe -mode hcp://system/sysinfo/msinfo.xml", 1, true



Post a Comment