Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing installed version with downloaded MSI version

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
0
0
US
Hi,

I am trying to compare the currently installed Google Version via the registry with the version inside the latest one's internal MSI database. This code looks choppy and probably could stand some cleaning up. What I having trouble with is the if statement below that determines if the MSI gets installed. When the installed version is the same or greater it should simply exit. Right now it appears to be doing a re-install or repair. Can someone suggest what needs to be cleaned up?

'Check version of Chrome presently installed
strComputer = "."
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product where (Caption='Google Chrome')")
For Each objSoftware in colSoftware
wscript.echo objSoftware.Version
Next

'Check version of the downloaded MSI file
Dim Installer
Set Installer = CreateObject("WindowsInstaller.Installer")
'Open the MSI database. You may change the path information as you like.
Dim Database
Set Database = Installer.OpenDatabase("c:\windows\temp\GoogleChromeStandaloneEnterprise.msi", 0)
'Create the SQL statement for query
Dim SQL
SQL = "SELECT * FROM Property WHERE Property = 'ProductVersion'"
'Open the view and execute the SQL statement
Dim View
Set View = DataBase.OpenView(SQL)
View.Execute
'Fetch the record for the "ProductVersion" property
Dim Record
Set Record = View.Fetch
'Show the result.
MsgBox Record.StringData(2)
If objSoftware.Version < Record Then
WshShell.Run "msiexec.exe /I c:\windows\temp\GoogleChromeStandaloneEnterprise.msi env=prod /qb!"
End If

If objSoftware > Record Then
WScript.echo "Installed version is same or newer than downloaded version"

End If

Thanks kindly.
 
I would start by determining the exact values of objSoftware.Version and Record, and then determine why objSoftware.Version < Record is not returning the value that you are expecting.

Also for readability, please surround your code in [ignore]
Code:
[/ignore] tags.
 
Let me start with the top portion of the code that deals with the registry. It does return the version installed correctly via the echo command. The bottom portion of the code that deals with querying the MSI file that too confirms the version that was downloaded with the msg box command.

If the 'version' (registry) is older than the 'record' (MSI internal DB query) then it should run the WshShell.Run command to install the newest Chrome. That works when the installed Chrome is older than the Chrome in the MSI file. What is not happening is I don't think it is even getting to the 2nd If statement when the installed Chrome is the same or newer than the one in the MSI. I see a repair or reinstall being done. That leads me to believe the first If-Else is incorrect somwhere. Do keep in mind these were 2 separate vbscripts that I tried to merge together.

You may have already put the pieces together in your head as well and I am not trying to sound like a record skipping. I am trying to reason this out in my head by writing this out again.

 
The > operator performs an alphabetic comparison if used on two strings, which often will not work with version numbers. You may need to break each part of the version up and compare each part. Depends on what objSoftware.Version and Record contain. The link below illustrates one way.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top