Answered by:
Batch Script to Compare Software Versions

Question
-
Hey Scripting Guys!
I have a question regarding writing a batch script that allows me to compare application versions. I'm creating a batch script that will install a WebEx application across my environment. I'm finding that the install will fail if the version already on the host is newer than what is being installed. I've been trying to conform the following into something like "If Webex Productivity tools version is greater than 2.32, skip install":
wmic product where "Name like '%WebEx%'" get Name, Version
wmic product where "Version like '%2.32%'" get Name, Version
In PowerShell this would be a piece of cake, but I have to use batch since we have XP OS's in our environment, unfortunately.
Any suggesstions? Many Thanks!
- Moved by Bill_Stewart Tuesday, February 17, 2015 11:11 PM This is not support forum for third party software
Tuesday, January 13, 2015 5:35 PM
Answers
-
This is going to be challenging using shell scripting (batch) only. I would think that VBScript or JScript would be a superior choice.
However, your question is really related to management of a specific application. I would start with the vendor for recommendations.
-- Bill Stewart [Bill_Stewart]
- Marked as answer by Bill_Stewart Tuesday, February 17, 2015 11:11 PM
Tuesday, January 13, 2015 5:44 PM
All replies
-
This is going to be challenging using shell scripting (batch) only. I would think that VBScript or JScript would be a superior choice.
However, your question is really related to management of a specific application. I would start with the vendor for recommendations.
-- Bill Stewart [Bill_Stewart]
- Marked as answer by Bill_Stewart Tuesday, February 17, 2015 11:11 PM
Tuesday, January 13, 2015 5:44 PM -
WMI works just the same against XP. WMIC is not any differnet it is just a wrapper around WMI the same as Powershell.
Get-WmiObject WIn32_Product -filter "Name like "%Webex%" AND Version like "2.32"' -Computer PC01,PC02,PC03...-
The installer failure is not an issue. It is designed to do that. If yo want to downgrade you have to specify an uninstall and reinstall on the command line.
¯\_(ツ)_/¯
- Edited by jrv Tuesday, January 13, 2015 5:56 PM
Tuesday, January 13, 2015 5:55 PM -
In PowerShell this would be a piece of cake, but I have to use batch since we have XP OS's in our environment, unfortunately.
As others have observed, this is messy with shell scripts. Much of the mess is caused by WMIC outputting its data with a variable column width which makes life tough for batch files. If you squeeze the very last drop of out the batch lemon then you can probably do it, e.g. like so:
@echo off
goto Start
-------------------------------------------------------------------
Use WMIC to determine the version number for the specified products.
13 Jan 2015 FNL
-------------------------------------------------------------------
:Start
set PR1='msvcrt'
set PR2='Microsoft security client'
set PR3='Catalyst Control Center Localization All'
wmic product where "Name=%PR1% Or Name=%PR2% or Name=%PR3%" get Name, Version > "%temp%\Products.txt"
rem set p=column width
for /F "delims=" %%a in ('type "%temp%\Products.txt"') do set Header=%%a & goto ColWidth
:ColWidth
set q=1
:Loop
call set Line=%%Header:~%q%%%%
set /a p=%q%-1
if "%Line:~0,7%"=="Version" goto GetVersion
set /a q +=+1
goto Loop
:GetVersion
for /F "skip=1 delims=" %%a in ('type "%temp%\Products.txt"') do call :sub %%a
goto :eof
:Sub
set Line=%*
call set Product=%%Line:~0,%p%%%%
call set Version=%%Line:~%q%%%%
echo Product=%Product%
echo Version=%Version%- Proposed as answer by Frederik Long Thursday, January 15, 2015 9:18 AM
Tuesday, January 13, 2015 7:22 PM