DosTips.com

A Forum all about DOS Batch
It is currently 22 Nov 2017 12:44

All times are UTC-06:00




Post new topic  Reply to topic  [ 17 posts ]  Go to page 1 2 Next
Author Message
 Post subject: Ver check & install
PostPosted: 19 Feb 2013 02:42 
Offline

Joined: 13 Sep 2012 00:05
Posts: 22
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 ..


Top
   
 Post subject: Re: Ver check & install
PostPosted: 19 Feb 2013 03:17 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
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.


Top
   
 Post subject: Re: Ver check & install
PostPosted: 19 Feb 2013 04:05 
Offline

Joined: 13 Sep 2012 00:05
Posts: 22
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,


Top
   
 Post subject: Re: Ver check & install
PostPosted: 19 Feb 2013 04:07 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
You must forgot to add empty line at the end of your batch, i instated that in the batch


Top
   
 Post subject: Re: Ver check & install
PostPosted: 19 Feb 2013 06:42 
Offline

Joined: 13 Feb 2013 14:02
Posts: 70
Location: Europe
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


Top
   
 Post subject: Re: Ver check & install
PostPosted: 19 Feb 2013 06:45 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
That's a lot faster than the WMIC


Top
   
 Post subject: Re: Ver check & install
PostPosted: 19 Feb 2013 21:23 
Offline

Joined: 13 Sep 2012 00:05
Posts: 22
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)


Top
   
 Post subject: Re: Ver check & install
PostPosted: 20 Feb 2013 00:41 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
To replace the _ sign,
first in the for command set the result to a variable.
Quote:
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:
Quote:
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 :)


Top
   
 Post subject: Re: Ver check & install
PostPosted: 20 Feb 2013 03:36 
Offline

Joined: 13 Sep 2012 00:05
Posts: 22
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.


Top
   
 Post subject: Re: Ver check & install
PostPosted: 20 Feb 2013 03:40 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
what is the output of these two commands:
Code: Select all
echo %Comparever%
echo "%CurrVer%"


Top
   
 Post subject: Re: Ver check & install
PostPosted: 20 Feb 2013 04:31 
Offline

Joined: 13 Sep 2012 00:05
Posts: 22
G:\>Me.bat
A=B
1 ------------- %Comparever%
"17001 "
------------- %CurrVer%
Press any key to continue . . .
Up to date


Top
   
 Post subject: Re: Ver check & install
PostPosted: 20 Feb 2013 04:39 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
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"


Top
   
 Post subject: Re: Ver check & install
PostPosted: 20 Feb 2013 20:03 
Offline

Joined: 13 Sep 2012 00:05
Posts: 22
Thanks abc0502
i got it clear now.. 8)


Top
   
 Post subject: Re: Ver check & install
PostPosted: 01 Mar 2013 00:59 
Offline

Joined: 13 Sep 2012 00:05
Posts: 22
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"


Top
   
 Post subject: Re: Ver check & install
PostPosted: 01 Mar 2013 01:20 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 6033
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"


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 17 posts ]  Go to page 1 2 Next

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited