title: Script to check the system for already installed program and its version
body: <p>I came upon a task of writing a script which first initiates a silent installation of Websphere MQ client 32 bit on a windows server. Then check if the installation was successful or not.....
  So I wrote the following script:</p>
  
  <pre class="lang-sh prettyprint-override"><code>  @echo off
    REM Author : Akshay Sinha
    REM Date Created : 07/05/2012
    REM Installing Websphere MQ.......
    Msiexec /q /i "%CD%\MSI\IBM WebSphere MQ.msi" /l*v .\install.log /m mif_file             TRANSFORMS="1033.mst" AGREETOLICENSE="yes"
    echo Script to check if the installation failed !!!
    echo Waiting for installaion to complete.......
    REM Script will wait for 2 mins, This is to ensure that install.log gets fully             generated.
    ping 123.45.67.89 -n 1 -w 120000 &gt; nul
    echo Wait Over
    find /C "Installation operation failed" "%CD%"\install.log &gt; tmp.log
    for /f "tokens=1,2,3 delims=:" %%a in (tmp.log) DO (
    SET /a FOUND_STR=%%c
    echo %FOUND_STR%
    )
    del tmp.log
    SET %FOUND_STR%=%FOUND_STR: =%
    echo %FOUND_STR%
    if %FOUND_STR% EQU 0 (
    echo Installation Of MQ completed without any errors!!!!!
    EXIT /B 0
    )
    if %FOUND_STR% GTR 0 (
    echo There were errors while installing MQ.. Pls Verify!!!
    EXIT /B 1
    )
  </code></pre>
  
  <p>the script is working fine for a fresh installation. ie if the mentioned software was not installed on the system already.</p>
  
  <p>However, I need to enhance this script such that, it should check the system for existing installations of Websphere MQ and its version.
  --if the version is not the one which we require(which of course , i will provide from command line) , it should initiate a uninstallation.</p>
  
  <p>The problem is I don't want to use the approach of searching the file system.
  So how do I accomplish this task using WMI classes.?? I looked up Win32_Product class, but it only returned me one installed program(Although, I have arnd 40 applications installed on my system).So I want to know:
  1)what is the concrete method of searching for a particular program on a system.(I am open to VbScripting or batch programming)
  2)Does the value of registry key for a installed software remains same across all systems and does it differ with different virsions??</p>
  
  <p>Thanks in advance.</p>