Check for Installed Applications - VB Script
Application installation can become tricky at times. We have noticed problems with installing software and our Spy Sweeper blocking the installation. We then had a need to determine if the Spy Sweeper is installed and do some action if it is.
Thus I created a little script that will go out and check to see if a particular application is installed on a computer. First I will show the full VBS script, then go over some modifications you might have to make.
'This script outputs to a .tsv file a list of applications installed on the computer
'Output file is software.tsv
'Usage: cscript applications.vbs
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("C:\WINDOWS\system32\temp\software.tsv", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
& "Version"
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & _
objSoftware.Description & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate2 & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.InstallState & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.SKUNumber & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version
Next
objTextFile.Close
'This searches for a string of txt in a file
Dim FoundIt 'as boolean
FoundIt=false 'initialize it to false
With createobject("Scripting.FileSystemObject")
on error resume next
FoundIt = (InStr(1,.OpenTextFile("C:\WINDOWS\system32\temp\software.tsv",1,true,-2).ReadAll,"Microsoft .NET Framework 2.0",1) <> 0)
on error goto 0
End With
'wscript.echo FoundIt
If FoundIt Then
wscript.echo "true"
Else
wscript.echo "false"
End If
As you will notice, I'm dumping the results of the script in C:\WINDOWS\system32\temp\ You may change this directory to any other location.
Also, you will need to change the line Microsoft .NET Framework 2.0. This is an example where I was checking to see if Microsoft .NET Framework 2.0 was installed. You will want to change this value to the application you are looking for.
Another area where you can get really creative with the script is the IF ELSE statement.
Currently I put echo statements in there as a template. Most likely I would have this statement do the action I wanted if the application was found such as uninstall or add additional files.
That's pretty much it. Some minor changes and this can be a powerful script for anybody. Thought I would share. If you have questions please come into the Altiris Juice Chat, my nick is MtBiker.
- Login or register to post comments
- 2735 reads
- Printer-friendly version
















Using WiseScript Express to check for installed applications
This can be done with 2-3 lines of code instead of using VB Script.
Example to check if spysweeper is installed and if so kill the task (I do not know the exact names of the spysweeper files or task, this is an example only):
Create 2 variables
The one good thing about WiseScript Express, is that it is a stupid script.
If the file
C:\Program Files\Spysweeper\spysweep.exe does not exist, the script dooes not fail. The script just does not run the taskkill.exe program and you do not receive a fail message.
When you use WiseScript Express, you compile the WSE file and receive an EXE file. You would include this EXE file in your MSI package you are installing, and to have run after INSTALLVALIDATE but before INSTALLINITIALIZE.
KJ
www.wisepackager.com