Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.
Endpoint Management Community Blog

Check for Installed Applications - VB Script

Created: 18 Aug 2008 • Updated: 18 Aug 2008 • 5 comments
MtBiker's picture
+1 1 Vote
Login to vote

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 & _

'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"
  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.

Comments 5 CommentsJump to latest comment

kjordan's picture

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

SOURCE = C:\Program Files\Spysweeper
SOURCE2 = C:\Windows\System32

IF File exists
Execute Program
%SOURCE2%\taskkill.exe /F /IM spysweeper.exe

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.



Login to vote
JonClone's picture

Thanks for posting about doing a check for installed applications using VB Script. I think some people wonder what happen to the software programs they install and whether are the programs really saved in the computer. I am currently checking updates on Groupon and the clone sites of it.

Jon Clone - Groupon Clone

Login to vote's picture

Thanks for your good share. i'm also faced that issue. I think it may help me.


Frank Vincent - clone script

Login to vote
Randy in Marin's picture

I now this is an old post; however, think twice before using Win32_Product.

Microsoft technet – “Don’t use Win32_Product”

I'm looking at this post because EVault GPO appears to be using this.  I do see the msi installer events every time policy is applied.

Login to vote
Hospity's picture

This is Great Coding Technique.. Very Interesting.. Its very useful for me. Thanks

Login to vote