Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

batch file that check version in registry

- - - - -

  • Please log in to reply
30 replies to this topic

#1
ceez

ceez

    Senior Member

  • Members
  • PipPipPipPip
  • 581 posts
Hello fellow msfn-ers!

I have a task I am trying perform using good ol' batch file commands (i've yet to learn WMI scripting! :( ).

What I want to do is for the script to check if the latest version of qtime is installed. In the registry the path is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties]


The key:

"DisplayVersion"="7.4.0.91"


How can I have an IF / THEN / GOTO command (or any other) incorporated to check this key?

I was thinking about trying an export but an export cant check the value of the key (can it?)

Thanks for your help...in the meanwhile I continue my google search!

ceez:
thumbup


How to remove advertisement from MSFN

#2
ceez

ceez

    Senior Member

  • Members
  • PipPipPipPip
  • 581 posts
ok so far I can get DOS to output the version# with the following cmd:

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties /v DisplayVersion


The output is the following:

C:\>reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\
S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties /v DisplayV
ersion

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\
S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA\InstallProperties
DisplayVersion REG_SZ 7.4.0.91


Now how can I make a line that says something like:
If DisplayVersion not equal to 7.4.0.91 then install "c:\apps\QuickTime740Installer.exe"

thanks again.

#3
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Try something like this:
@Echo OffSetlocalSet "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData"Set "key=%key%\S-1-5-18\Products\2C478CE6059FE7B45A7B1B60D6B647AA"Set "key=%key%\InstallProperties"For /f "tokens=3 delims=	" %%# In (	'Reg query %key% /v DisplayVersion^|Find "REG_" 2^>Nul') Do Set "rel=%%#"If Not [%rel%]==[7.4.0.91] Start "" /wait C:\apps\QuickTime740Installer.exeEndlocalGoto :Eof
Where delims=<TAB>"

#4
ceez

ceez

    Senior Member

  • Members
  • PipPipPipPip
  • 581 posts
@Yzowl, WOW how long did it take you to come up with that?!?! I am not at work so cant try it out but will tomorrow. could it be possible for you explain a little bit what each line does? I regards to the "delim" section you're saying that I should press the TAB key there and not just empty spaces? And where did you learn all this batch coding?

Man thanks again, hope it works.

ceez
:thumbup

#5
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Now aren't I glad I gave you a longer but easier to understand solution...

Lines 1 & 2 turn off echoing to the console and ensure that all variables are locally set.
Lines 3, 4 & 5 is my way of setting the key you gave for the registry data we're looking for. It is considered good practice when coding to maintain maximum character line lengths, in this case 80 characters; so I've split it across 3 lines for this reason.

The For loop is where it gets interesting...

I took your reg query command and put it inside the parentheses.
because your output produced more than one line I needed to capture only the line containing your version data so I sent the result of the reg query through a find command to pick up the line containing REG_
the output of the data is TAB delimited (delims=<TAB>) into distinct columns.
the data you wanted was in the third column (tokens=3)

Basically any data in third column of that key will be set to the local variable %rel%

All we do then is a simple `if result of query is not our data then perform this task` line.

For that line, i.e. your installation, you could see if you can use silent switches too, this would remove any end-user interaction!

#6
ceez

ceez

    Senior Member

  • Members
  • PipPipPipPip
  • 581 posts
excellent explanation, thank you very much.

I just tried it and it works perfectly! I tried it on my workstation which has that version and it does not run, if I modify the version number on my registry and try to run it again it will begin the setup. Yes, I will be adding the /q switch for a silent installation.

Now I have the same thing to do with with Java 6.3... I should be able to follow the same concept :)

thanks alot for your help!

ceez

#7
Xaneth

Xaneth

    Newbie

  • Members
  • 11 posts
I'm trying to do the same thing, but I'm still not seeing how you're setting tab as the delimiter. Do you put spaces in, or just hit tab, or use "delims=<tab>"? I'm just trying to update our Adobe Flash player, and looking for version 9.0.124.0 under the key hklm\software\microsoft\active setup\installed components\{d27cdb6e-ae6d-11cf-96b8-444553540000}. When I run the command by hand, I'm also getting %%# was not expected at this time.

#8
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

You just use the Tab key, I needed to explain in that way because the forum software sometimes converts the tab I input into a series of spaces.

When you run the command manually in a console window, you'll need to replace all instances of %%# with %#.

#9
Xaneth

Xaneth

    Newbie

  • Members
  • 11 posts

===== Post N 1 =====


Thanks for that. The tab and %# work for me now, but I get an error in my reg query syntax now. I'm essentially trying to perform the following with my query:

reg query %key% /s | find "Version"

I try to pass it the way you wrote:

'Reg query %key% /v DisplayVersion^|Find "REG_" 2^>Nul'

But I'm getting the same error, Type "REG QUERY /?" for usage. I've tried it multiple ways as well since it doesn't seem to understand the pipe too well, I tried

'Reg query %key% /s DisplayVersion^|Find "Version" 2^>Nul'
'Reg query %key% /v DisplayVersion^|Find "Version" 2^>Nul'
'Reg query %key% /s Version^|Find "Version" 2^>Nul'
'Reg query %key% /s Version^|Find "reg_" 2^>Nul'

None of which seem to work.

===== Post N 2 =====


OK, I managed to get it working somewhat with:

reg query "%key%" /v Version^|find "REG_"

This is because my registry path has spaces in it. I am still not getting the results intended however, as the executable is not launching. Not sure what I'm doing wrong here but still pounding away at it. What is returned after typing that command is:

Version REG_SZ 9.0.124.0

In fact the full command I'm trying to execute is:

for /f "tokens=3 delims= " %# In ('reg query "%key%" /v Version^|find "REG_" 2^>Nul') do set "rel=%#" if not [%rel%]==[9.0.115.0] start "" /wait "fileservershareflash.msi"

Since I have version 9.0.124.0, the installer should run for me but it's not.

Edited by Yzwl, 12 June 2008 - 05:31 PM.


#10
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Apologies for not answering his sooner Xaneth, I've no idea how I missed your question.

Here are two solutions, one for each key, (I'd suggest the latter)

Uninstall key version

@Echo Off&Setlocal
Set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Set "key=%key%\Adobe Flash Player Plugin"
For /f "tokens=3 delims=	" %%# In (
  'Reg query "%key%" /v DisplayVersion^|Find "REG_" 2^>Nul') Do Set "rel=%%#"
If Not [%rel%]==[9.0.115.0] Start "" /wait \\fileserver\share\flash.msi
Endlocal&Goto :Eof

plugins key version

@Echo Off&Setlocal
Set "key=HKLM\SOFTWARE\MozillaPlugins\@adobe.com/FlashPlayer"
For /f "tokens=3 delims=	" %%# In (
  'Reg query %key% /v Version^|Find "REG_" 2^>Nul') Do Set "rel=%%#"
If Not [%rel%]==[9.0.115.0] Start "" /wait \\fileserver\share\flash.msi
Endlocal&Goto :Eof

Note
Don't forget that delims=<tab>" in both versions

I hope this helps!

I'll leave it to you to explain, if you wish, why you'd attempt to install 9.0.115.0 over 9.0.124.0

#11
Xaneth

Xaneth

    Newbie

  • Members
  • 11 posts
Thanks a lot, I'll give it a try as soon as I get some time! The reason I was doing it this way, was to test the installation to make sure it would kick off, since I don't want to downgrade just to test this out. I'll be replacing:

If Not [%rel%]==[9.0.115.0] Start "" /wait \\fileserver\share\flash.msi

with

If Not [%rel%]==[9.0.124.0] Start "" /wait \\fileserver\share\flash.msi

Edited by Xaneth, 13 June 2008 - 11:30 AM.


#12
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Just remember to get time quickly because I've already seen leaked versions of flash v10.0.1.218 circulating the net…

#13
jxhzhang

jxhzhang
  • Members
  • 4 posts
Hello, I'm new but I'm trying to do the exact same thing but there is a twist to this.

I'm trying to do an uninstall for Adobe Reader 7.0.9 or Reader 7.1.0. The thing is 7.0.9 uses this key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A70900000002} while 7.1.0 use this HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A71000000002}. How would I check if 7.0.9 doesn't exist then check 7.1.0?

Right now REG would return an error while checking for 7.0.9 (because it doesn't exist on a machine with 7.1.0 installed). How would I go about to get around that?

Thanks,
James

#14
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Here's a quick stab at what I think you want:
@Echo off&SetlocalSet "kb_=HKLM\SOFTWARE\Adobe\Acrobat Reader"Set "ke_=Installer\{AC76BA86-7AD7-"Set "uk_=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"For /f "tokens=2 delims={" %%# In (	'Reg query "%kb_%" /s^|find "%ke_%" 2^>Nul') Do Call :_ {%%#Endlocal&Goto :Eof:_Set "t_=%uk_%\%1"Reg query %t_% /v DisplayVersion|Findstr "7.0.9 7.1.0">Nul 2>&1||(Set "t_="	Goto :Eof)For /f "tokens=3 delims=	" %%# In (	'Reg query %t_% /v UninstallString') Do Start "" /wait "%%~#"
The intention is that it'll uninstall either version 7.0.9 or 7.1.0 if either one of them exist!

Let us know how it goes.

Note
Remember when you paste it in that delims=<tab>" in the last 'For loop'.

#15
jxhzhang

jxhzhang
  • Members
  • 4 posts

Here's a quick stab at what I think you want:

@Echo off&SetlocalSet "kb_=HKLM\SOFTWARE\Adobe\Acrobat Reader"Set "ke_=Installer\{AC76BA86-7AD7-"Set "uk_=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"For /f "tokens=2 delims={" %%# In (	'Reg query "%kb_%" /s^|find "%ke_%" 2^>Nul') Do Call :_ {%%#Endlocal&Goto :Eof:_Set "t_=%uk_%\%1"Reg query %t_% /v DisplayVersion|Findstr "7.0.9 7.1.0">Nul 2>&1||(Set "t_="	Goto :Eof)For /f "tokens=3 delims=	" %%# In (	'Reg query %t_% /v UninstallString') Do Start "" /wait "%%~#"
The intention is that it'll uninstall either version 7.0.9 or 7.1.0 if either one of them exist!

Let us know how it goes.

Note
Remember when you paste it in that delims=<tab>" in the last 'For loop'.


Thank you for a quick response! Took me a bit of time to understood what the code does. You are taking the UninstallString from registry and running it, but I need it to be silent (using the /x and end with -qb instead of /i). Also when I ran the batch you've created, I get this

Posted Image

Not sure why it gives you that error because I executed the UninstallString with Run and works fine. So is it possible to do the batch above and silent uninstall (with progress window)? Thanks again!

#16
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Initially to fix the supplied script, try this:
 
@Echo off&Setlocal
Set "kb_=HKLM\SOFTWARE\Adobe\Acrobat Reader"
Set "ke_=Installer\{AC76BA86-7AD7-"
Set "uk_=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
For /f "tokens=2 delims={" %%# In (
'Reg query "%kb_%" /s^|find "%ke_%" 2^>Nul') Do Call :_ {%%#
Endlocal&Goto :Eof
:_
Set "t_=%uk_%\%1"
Reg query %t_% /v DisplayVersion|Findstr "7.0.9 7.1.0">Nul 2>&1||(Set "t_="
Goto :Eof)
For /f "tokens=3 delims= " %%# In (
'Reg query %t_% /v UninstallString^|Find "REG_"') Do Start "" /wait %%#


#17
jxhzhang

jxhzhang
  • Members
  • 4 posts
Yes it fixed the issue. Thank you!

So I've looked around for string manipulation in batch files but the results came up pretty dry. Any idea on how to change the UninstallString from "MsiExec.exe /I{AC76BA86-7AD7-1033-7B44-A71000000002}" to "MsiExec.exe /x {AC76BA86-7AD7-1033-7B44-A71000000002} -qb"?

Cheers!

#18
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Instead of using the 'For loop' at the bottom of the script, change it to just something like this:
Start "" /wait MsiExec.exe /x %1 /qb


#19
jxhzhang

jxhzhang
  • Members
  • 4 posts

Instead of using the 'For loop' at the bottom of the script, change it to just something like this:

Start "" /wait MsiExec.exe /x %1 /qb


Well I feel a bit dumb :rolleyes:

You are great help. Thanks again! :thumbup

#20
pmuir

pmuir
  • Members
  • 1 posts
Hi Yzowl, sorry to bring a post that was practically dead back to life but i was wondering if you would be able to help me.

Iv been working on a batch file to try and automate the new XP SP3 upgrade, amongst other things. I have found your code and have been trying to alter it to find the IE version. I have had no luck so far and was wondering if you could have a look at it and let me know what I was doing wrong.

Thanks in advance for any and all help (not just from Yzowl of course)

Here is what I have done so far....

 
Setlocal
Set "key=HKLM\SOFTWARE\Microsoft\Internet Explorer\Version Vector"
For /f "tokens=3 delims= " %# In (
'Reg query %key% /v IE ^|Find "7.0000" 2^>Nul') Do Set "rel=%#"
If Not [%rel%]==[7.0000] Start ""/w IE7\IE7-WindowsXP-x86-enu.exe


Just a bit of background, im using a USB pen to try to make the installation as easy as possible which is why the .exe is where it is..

If you need any more information about it please dont hesitate to ask..

Thanks

Paul

#21
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

@pmuir, something like this should do you!
@Echo off&Setlocal

Set k_="HKLM\SOFTWARE\Microsoft\Internet Explorer"

For /f "skip=3 tokens=3 delims=	." %%# In ('Reg query %k_% /v Version') Do Set v_=%%#

If %v_% Lss 7 Start "" /w IE7\IE7-WindowsXP-x86-enu.exe
where delims=<TAB><DOT>

#22
jaclaz

jaclaz

    The Finder

  • Developers
  • 13,382 posts
  • OS:none specified
  • Country: Country Flag
Apart the as always good solution by Yzwl, a general advice is:

Do it in steps.

First thing read this:
http://www.robvander...tfortokens.html

Then simply run:

Reg query "HKLM\SOFTWARE\Microsoft\Internet Explorer\Version Vector"


Then try with something like:
SET KEY="HKLM\SOFTWARE\Microsoft\Internet Explorer\Version Vector"
FOR /F "tokens=1,2,3 delims=	" %%A in ('Reg query %KEY%' ) DO (
ECHO %%A
ECHO %%B
ECHO %%C
)

Then try with:
FOR /F "tokens=1,2,3 delims=	" %%A in ('Reg query %KEY%^|FIND "IE"' ) DO (
ECHO %%C
)

...and then refine it a bit more, adding the check, etc.....


(Usually I prefer to use the FIND for the line instead of the skip, but it is just a matter of tastes in this case)

jaclaz

#23
luppybob

luppybob
  • Members
  • 4 posts
I am trying to do a similar thing, but my Reg Query output starts off with 4 spaces and also has a delimiter of 4 spaces, as shown below. Any idea how I can get this to work?

Input is:
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1" /v DisplayVersion

Output is:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1
DisplayVersion REG_SZ 3.1.3

I tried these lines in the batch file, but it did not work:
For /f "tokens=3 delims= " %%# In (
'Reg query "%key%" /v DisplayVersion^|Find "REG_" 2^>Nul') Do Set "rel=%%#"
If [%rel%]==[3.1.3] echo version 3.1.3 is installed

Thanks in advance for anyone's assistance.

#24
Yzwl

Yzwl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

@ luppybob
First thing to note is that if your output contains spaces instead of tabs, (which it generally does in Vista), but none of your tokens do, then use both space and tab as your delimiters i.e. delims=<tab><space>

You may however be over-complicating your approach, since you are looking for a specific version number why not use that as your Find and ignore the For loop completely!
@Echo off&Setlocal
Set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1"
Reg query %key% /v DisplayVersion|Find "3.1.3">Nul&&(
	Echo:version 3.1.3 is installed)


#25
luppybob

luppybob
  • Members
  • 4 posts
Hello,

Thank you for your effort and prompt reply -- THIS DID WORK!

Can you help me with one additional thing in this script:

Basically, I want to do a couple of things if 3.1.3 is found. You had combined it in such a way, I am having difficulty inserting an "IF" statement.

Say I want to do this:
If [3.1.3] is found (
echo version 3.1.3 is installed
c:\install\Snare314.exe
c:\install\Snare314patch.exe
echo version 3.1.4 successfully installed
)

Thanks again for your great help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN