Jump to content

batch file that check version in registry


Recommended 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

Link to comment
Share on other sites


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.

Link to comment
Share on other sites

Try something like this:

@Echo Off
Setlocal
Set "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.exe
Endlocal
Goto :Eof

Where delims=<TAB>"

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 months later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

===== 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 Yzöwl
Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

@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') 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'.

Link to comment
Share on other sites

  • 3 weeks later...
Here's a quick stab at what I think you want:
@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') 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

msiexec.jpg

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!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...