Submitted By: Emanuele Marenco

Retrieves information about the software installed on a computer and then saves that information to a text file.

Visual Basic
Edit|Remove
' Emanuele Marenco
' Writing Installed Products on a Text File 
' Windows Server 2003 : Yes 
' Windows XP : Yes 
' Windows 2000 : Yes 
' Windows NT 4.0 : Yes 
' Windows 98 : Yes 
' This is a script that collects all the installed products on a text file.
' the file can be selected by browsing ( on S.O. XP ) or writing it in the inputbox; the file is a tab separate value file


Const ForAppending = 8
Dim objWMIService
strComputer = "."
strTargetFile = "c:\InstalledProducts.txt"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strTargetFile = GetDestinationFile
Set objTextFile = objFSO.OpenTextFile(strTargetFile, ForAppending, True)

Set colItems = objWMIService.ExecQuery("Select * from Win32_Product")


	
   StrInstallation = "Caption:" & vbTab &  _
      "Description:" & vbTab &  _
      "InstallDate:" & vbTab &  _
      "InstallDate2:" & vbTab &  _
      "InstallLocation:" & vbTab &  _
      "InstallState:" & vbTab & _
      "Name:" & vbTab &  _
      "PackageCache:" & vbTab & _
      "SKUNumber :" & vbTab & _
      "Vendor :" & vbTab &  _
      "Version :" & vbTab 
      objTextFile.WriteLine StrInstallation

For Each objItem in colItems
   StrInstallation = objItem.Caption & vbTab & _ 
       objItem.Description & vbTab & _ 
       objItem.InstallDate & vbTab & _ 
       objItem.InstallDate2 & vbTab & _ 
       objItem.InstallLocation & vbTab & _ 
       objItem.InstallState & vbTab & _ 
       objItem.Name & vbTab & _ 
       objItem.PackageCache & vbTab & _ 
       objItem.SKUNumber & vbTab & _ 
       objItem.Vendor & vbTab & _ 
       objItem.Version 
       objTextFile.WriteLine StrInstallation
Next
objTextFile.Close


Private Function GetDestinationFile()

Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
	If objOperatingSystem.Caption  = "Microsoft Windows XPProfessional" Then
		FileName = GetDestinationFileXP		
	Else
		Dim oWshShell
		Set oWshShell = CreateObject("wscript.Shell")
		FilePath = oWshShell.SpecialFolders("MyDocuments"&"\InstalledProducts.txt"
		FileName = InputBox("Insert here the path to the TargeFile","Installed Products", FilePath ) 
		Set oWshShell = Nothing
	End If
Next
	GetDestinationFile = FileName
End Function

Private Function GetDestinationFileXP()
'Locate a File Using a File Open Dialog Box
'On Windows XP (only) it can be used the 
	Set objDialog = CreateObject("UserAccounts.CommonDialog")
	Dim oWshShell
	Set oWshShell = CreateObject("wscript.Shell")

	objDialog.Filter = "Text File|*.txt|Tab Separate ValueFile|*.tsv|All Files|*.*"
	objDialog.FilterIndex = 1
	objDialog.InitialDir = oWshShell.SpecialFolders("MyDocuments")
	intResult = objDialog.ShowOpen
 
	If intResult = 0 Then
    	GetDestinationFileXP = vbNullString
	Else
     	GetDestinationFileXP = objDialog.FileName
	End If
	Set oWshShell = Nothing
	Set objDialog = Nothing
End Function