Ver check & install

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Dipesh
Posts: 23
Joined: 13 Sep 2012 00:05

Ver check & install

#1 Post by Dipesh » 19 Feb 2013 02:42

hello to all,

I am looking for code that check flash version if version is lower then Current version it install flash if not then exit..

Here my code...

To check the Version (i want this code batch file if possible)
ver.vbs
=====
On Error Resume Next
Const strComputer = "."
Const HKLM = &H80000002
Const strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Dim oReg, arrSubKeys, strProduct, strDisplayName, strVersion
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
' Enumerate the subkeys of the Uninstall key
oReg.EnumKey HKLM, strKeyPath, arrSubKeys
For Each strProduct In arrSubKeys
' Get the product's display name
oReg.GetStringValue HKLM, strKeyPath & "\" & strProduct, "DisplayName", strDisplayName
' Process only products whose name contain 'Flash'
If InStr(1, strDisplayName, "Flash", vbTextCompare) > 0 Then
' Get the product's display version
oReg.GetStringValue HKLM, strKeyPath & "\" & strProduct, "DisplayVersion", strVersion
WScript.Echo strVersion
End If
Next

From this vb script i got ver.txt looks like :
11.5.502.149
11.5.502.149

Now i read this file form dos :

FOR /F "tokens=1 delims=," %%G IN (ver.txt) DO @echo %%G

now i looking for

if not "%%G" == 12.0.1 then goto install else exit...

Like if i defined version in batch file is Higher version or no version(blank ver.txt) then systems version then install flash or version is same then it exit.

example: if system current flash version is 11.0.0.1 then install flash player else same version then exit.

Thanks ..

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Ver check & install

#2 Post by abc0502 » 19 Feb 2013 03:17

Try This:

Code: Select all

@Echo OFF

SET "Version=12.0.1"

REM ====[ Get Ver.txt file ]=================
CALL :GetVer


REM ====[ Read and compare ]=================

rem convert Version to numbers without dot
FOR /F "tokens=1-4 delims=." %%A IN ("%Version%") DO SET "CompareVer=%%A%%B%%C"

rem convert version number from FlashVer.txt to numbers without dots
FOR /F "tokens=1-4 delims=." %%A IN ('Type "FlashVer.txt"') Do SET "CurrVer=%%A%%B%%C"

rem compare and install
IF "%CompareVer%" GTR "%CurrVer%" (
   rem Add flash exe file location here
   echo  Installing Flash
   ) Else ( Echo   Up to date )

Del /F /Q "GetVer.vbs" "FlashVer.txt" >NUL
Ping localhost -n 6 >nul
Exit /B

:GetVer
IF Exist "FlashVer.txt" Del /F /Q "FlashVer.txt" >NUL
(For /F "tokens=1*" %%A In ('FINDstr "^:VBS: " ^< "%~F0"') DO Echo.%%B)>"%~dp0GetVer.vbs"
CScript //nologo "%~dp0GetVer.vbs"
GOTO :EOF
:VBS: Const strComputer = "."
:VBS: Const HKLM = &H80000002
:VBS: Const strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
:VBS: Dim oReg, arrSubKeys, strProduct, strDisplayName, strVersion
:VBS: Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
:VBS:  strComputer & "\root\default:StdRegProv")
:VBS: ' Enumerate the subkeys of the Uninstall key
:VBS: oReg.EnumKey HKLM, strKeyPath, arrSubKeys
:VBS: For Each strProduct In arrSubKeys
:VBS:  ' Get the product's display name
:VBS: oReg.GetStringValue HKLM, strKeyPath & "\" & strProduct, "DisplayName", strDisplayName
:VBS:  ' Process only products whose name contain 'Flash'
:VBS:  If InStr(1, strDisplayName, "Flash", vbTextCompare) > 0 Then
:VBS:  ' Get the product's display version
:VBS:  oReg.GetStringValue HKLM, strKeyPath & "\" & strProduct, "DisplayVersion", strVersion
:VBS: dim oFS, oFolder, objShell
:VBS: set oFS = WScript.CreateObject("Scripting.FileSystemObject")
:VBS: Set objShell = CreateObject("wscript.shell")
:VBS: Set fsHandle = oFS.OpenTextFile ("FlashVer.txt",8,True) 'external file
:VBS: fsHandle.Writeline strVersion
:VBS: End If
:VBS: Next

REM Leave Empty Line after this line


replace or add after this line "echo Installing Flash" the full location to your flash installer and when you set the version variable at the begining of the batch, make sure it consist of 3 parts seprated with a dot.
if you just have number 12 as in your example, write it that way 12.0.0

You can get the flash version fro wmic service without the need for the vbscript, but it's a bit slow.

Dipesh
Posts: 23
Joined: 13 Sep 2012 00:05

Re: Ver check & install

#3 Post by Dipesh » 19 Feb 2013 04:05

Thanks for the replay abc0502

i try above code but it stuck. it stuck when making vbs file.
even GetVer.vbs is generated but 0 bytes & prompt get stuck.

Any ideas dear,

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Ver check & install

#4 Post by abc0502 » 19 Feb 2013 04:07

You must forgot to add empty line at the end of your batch, i instated that in the batch

mfm4aa
Posts: 70
Joined: 13 Feb 2013 14:02
Location: Europe

Re: Ver check & install

#5 Post by mfm4aa » 19 Feb 2013 06:42

Version check without Basic:

Code: Select all

@echo off
for /f "tokens=2*skip=4" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player Plugin" /v DisplayVersion') do echo %%b
for /f "tokens=2*skip=4" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player ActiveX" /v DisplayVersion') do echo %%b


output:

Code: Select all

11.6.602.168
11.5.502.135

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Ver check & install

#6 Post by abc0502 » 19 Feb 2013 06:45

That's a lot faster than the WMIC

Dipesh
Posts: 23
Joined: 13 Sep 2012 00:05

Re: Ver check & install

#7 Post by Dipesh » 19 Feb 2013 21:23

mfm4aa thanks for the replay. & yes reg work the fast & reliable then wmic. It's work great.

But one more thing i do with this java version like

for /f "tokens=2*skip=4" %%a in ('reg query "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" /v Java7FamilyVersion') do echo %%b > JavaVer.txt

i got output:- 1.7.0_01

how i remove underscore ? 0_10 when compare with version ?

FOR /F "tokens=1-4 delims=." %%A IN ("%Version%") DO SET "CompareVer=%%A%%B%%C"
FOR /F "tokens=1-4 delims=." %%A IN ('Type "FlashVer.txt"') Do SET "CurrVer=%%A%%B%%C"


& Also for Firefox is like i got form reg :- 18.0.2 (en-US)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Ver check & install

#8 Post by abc0502 » 20 Feb 2013 00:41

To replace the _ sign,
first in the for command set the result to a variable.
for /f "tokens=2*skip=4" %%a in ('reg query "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" /v Java7FamilyVersion') do set "vers=%%b"

then echo the variable using this form:
Echo %var_name:A=B%

Var_name : is the variable name we just set in the previous step.
A (in red) : is the character in the content of the variable you need to change.
B (in blue): is the character that will be replaced with
( leave it empty to remove the sign like %vers:_=% "nothing between = and % signs" )

so when you echo the vers variable it looks like:

Code: Select all

Echo %vers:_=% > "JavaVer.txt"


in firefox, to remove the "(en-US)" and the space between it and the numbers you set it in the variable then take all characters in that variable except the last 8 characters like "%var:~0,-8%

i hope that's clear enough :)

Dipesh
Posts: 23
Joined: 13 Sep 2012 00:05

Re: Ver check & install

#9 Post by Dipesh » 20 Feb 2013 03:36

I don't know where i am wrong but command gose only on up to date... only....

here is code:-

@echo off
SET "Version=1"
CALL :GetVer
FOR /F "tokens=1-4 delims=." %%A IN ("%Version%") DO SET "CompareVer=%%A%%B%%C"
FOR /F "tokens=1-4 delims=." %%A IN ('Type "JavaVer.txt"') Do SET "CurrVer=%%A%%B%%C"
echo %Comparever%
echo "%CurrVer%"
pause
IF "%CompareVer%" GTR "%CurrVer%" (
rem Add flash exe file location here
echo Installing Flash
) Else ( Echo Up to date )

Ping localhost -n 6 >nul
Exit /B
:GetVer
for /f "tokens=2*skip=4" %%a in ('reg query "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" /v Java7FamilyVersion') do set "vers=%%b"
Echo %var_name:A=B%
Echo %vers:_=% > "JavaVer.txt"

Here is outpu:-

C:\>Main.bat
A=B
1
"17001 "
Press any key to continue . . .
Up to date

All gose Up to date only... please guide me.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Ver check & install

#10 Post by abc0502 » 20 Feb 2013 03:40

what is the output of these two commands:

Code: Select all

echo %Comparever%
echo "%CurrVer%"

Dipesh
Posts: 23
Joined: 13 Sep 2012 00:05

Re: Ver check & install

#11 Post by Dipesh » 20 Feb 2013 04:31

G:\>Me.bat
A=B
1 ------------- %Comparever%
"17001 "
------------- %CurrVer%
Press any key to continue . . .
Up to date

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Ver check & install

#12 Post by abc0502 » 20 Feb 2013 04:39

ok, There is some errors in you code, test this:

Code: Select all

@Echo OFF

SET "Version=1"

CALL :GetVer

SETLocal EnableDelayedExpansion
FOR /F "tokens=1-4 delims=." %%A IN ("%Version%") DO SET "CompareVer=%%A%%B%%C"
FOR /F "tokens=1-4 delims=." %%A IN ('Type "JavaVer.txt"') Do SET "CurrVer=%%A%%B%%C"

IF "%CompareVer%" GTR "%CurrVer%" (
 rem Add flash exe file location here
 echo Installing Flash
 ) Else ( Echo Up to date )

Ping localhost -n 6 >nul
Exit /B

:GetVer
for /f "skip=4 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" /v Java7FamilyVersion') do set "vers=%%b"
Echo %vers:_=% > "JavaVer.txt"


To use the GTR you must enable the delayed expnsion,
Also i said in a previous post that the "%version%" variable must be in this form X.0.0
so if you have only number 1, then write it that way "1.0.0" and if you have 1.2 then write it that way "1.2.0"
always make the number in the previous form.

But beware that this method won't be that accurate, if you set the version to 10.0.0 and the current version in your computer is 9.12.125 then when the batch compare it will compare between "1000" and "912125" and the last one is bigger. :(
so if it ok with you to just compare between 10 (10.0.0) and 9 (9.12.125) it will be more accurate.
just replace the two for command after each other with these:

Code: Select all

FOR /F "tokens=1 delims=." %%A IN ("%Version%") DO SET "CompareVer=%%A"
FOR /F "tokens=1 delims=." %%A IN ('Type "JavaVer.txt"') Do SET "CurrVer=%%A"

Dipesh
Posts: 23
Joined: 13 Sep 2012 00:05

Re: Ver check & install

#13 Post by Dipesh » 20 Feb 2013 20:03

Thanks abc0502
i got it clear now.. 8)

Dipesh
Posts: 23
Joined: 13 Sep 2012 00:05

Re: Ver check & install

#14 Post by Dipesh » 01 Mar 2013 00:59

another twist

i have currently installed firefox version 17.0.2.

So for update new version i have set version=19.0.1 (it is 19.0 only)

when i run the code it update first time bcoz 1901 GTR 1702.
But when i run again then it also install bcoz in registry firefox value is :- 19.0 (en-US)

then it bcom 1901 GTR 190... so it install every time.... any guideline for that please.

Here is code :-


SET "firefox=19.0.1"
CALL :GetVerfire
SETLocal EnableDelayedExpansion

FOR /F "tokens=1-4 delims=." %%A IN ("%firefox%") DO SET "javaCompareVer=%%A%%B%%C"
FOR /F "tokens=1-4 delims=." %%A IN ('Type "firefoxver.txt"') Do SET "javaCurrVer=%%A%%B%%C"

IF "%javaCompareVer%" GTR "%javaCurrVer%" (
\\172.16.109.18\test\update\fireup.exe
) Else ( exit )
Ping localhost -n 6 >nul
Exit /B
:GetVerfire

for /f "skip=4 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Mozilla\Mozilla Firefox" /v CurrentVersion') do set "vers=%%b"

Echo %vers:(en-US)=% > "firefoxVer.txt"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Ver check & install

#15 Post by foxidrive » 01 Mar 2013 01:20

SET "firefox=19.0.1"
CALL :GetVerfire
SETLocal EnableDelayedExpansion

FOR /F "tokens=1-4 delims=." %%A IN ("%firefox%") DO SET "javaCompareVer=%%A%%B%%C"
FOR /F "tokens=1-4 delims=." %%A IN ('Type "firefoxver.txt"') Do SET "javaCurrVer=%%A%%B%%C"

IF "%javaCompareVer%" GTR "%javaCurrVer%" (
\\172.16.109.18\test\update\fireup.exe
) Else ( exit )
Ping localhost -n 6 >nul
Exit /B
:GetVerfire

for /f "skip=4 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Mozilla\Mozilla Firefox" /v CurrentVersion') do set "vers=%%b"

Remove the dots?

set "vers=%vers:.=%"

Echo %vers:(en-US)=% > "firefoxVer.txt"

Post Reply