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