Sub FullListing()
Dim objFSO As Object
Dim objTextFile As Object
Dim strComputer As String
Dim objWMIService As Object
Dim colSoftware As Variant
Dim objSoftware As Object
Dim sOutputFile As String
sOutputFile = Environ("temp") & "\TempFileInfoFile.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(sOutputFile, True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("SELECT * FROM Win32_Product")
'Write Header to File
objTextFile.WriteLine "Name" & vbTab & "Version" & vbTab & "Vendor" & vbTab & _
"Caption" & vbTab & "Description" & vbTab & _
"IdentifyingNumber" & vbTab & "InstallDate" & vbTab & _
"InstallDate2" & vbTab & "InstallLocation" & vbTab & _
"InstallState" & vbTab & "HelpLink" & vbTab & _
"HelpTelephone" & vbTab & _
"InstallSource" & vbTab & _
"Language" & vbTab & _
"LocalPackage" & vbTab & _
"PackageCache" & vbTab & _
"PackageCode" & vbTab & _
"PackageName" & vbTab & _
"ProductID" & vbTab & _
"RegOwner" & vbTab & _
"RegCompany" & vbTab & _
"SKUNumber" & vbTab & _
"Transforms" & vbTab & _
"URLInfoAbout" & vbTab & _
"URLUpdateInfo" & vbTab & _
"WordCount"
'Write Data to File
For Each objSoftware In colSoftware
objTextFile.WriteLine objSoftware.Name & vbTab & objSoftware.Version & vbTab & objSoftware.Vendor & vbTab & _
objSoftware.Caption & vbTab & objSoftware.Description & vbTab & _
objSoftware.IdentifyingNumber & vbTab & objSoftware.InstallDate & vbTab & _
objSoftware.InstallDate2 & vbTab & objSoftware.InstallLocation & vbTab & _
objSoftware.InstallState & vbTab & objSoftware.HelpLink & vbTab & _
objSoftware.HelpTelephone & vbTab & _
objSoftware.InstallSource & vbTab & _
objSoftware.Language & vbTab & _
objSoftware.LocalPackage & vbTab & _
objSoftware.PackageCache & vbTab & _
objSoftware.PackageCode & vbTab & _
objSoftware.PackageName & vbTab & _
objSoftware.ProductID & vbTab & _
objSoftware.RegOwner & vbTab & _
objSoftware.RegCompany & vbTab & _
objSoftware.SKUNumber & vbTab & _
objSoftware.Transforms & vbTab & _
objSoftware.URLInfoAbout & vbTab & _
objSoftware.URLUpdateInfo & vbTab & _
objSoftware.WordCount
Next
objTextFile.Close
AddSheet sOutputFile
Kill sOutputFile
End Sub
Private Sub AddSheet(sOutputFile As String)
Dim oWS As Worksheet
Dim strComputer As String
Application.DisplayAlerts = False
On Error Resume Next
Worksheets("M4").Delete
On Error GoTo 0
Application.DisplayAlerts = True
Set oWS = Worksheets.Add(after:=Worksheets(Worksheets.Count))
With oWS
.Name = "M4"
.Range("$A$1") = "Computer : " & strComputer
'Ensure Text-to-Column has Tab as True and Space as False
Range("A1").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, _
FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
.Range("a1").Font.Bold = True
.QueryTables.Add(Connection:="TEXT;" _
& sOutputFile, Destination:=oWS.Range("$A$2")).Refresh
End With
End Sub