?
Solved

Help with a batch file script to query whether a registry key value exists

Posted on 2014-01-09
3
Medium Priority
?
399 Views
Last Modified: 2014-01-09
Hi all,

I need some help with a batch file to query whether a registry key value exists.  

If it does exist I want the script to end, but if it does not exist I want the script to execute an exe installation.

I know I have done this in the past but cannot quite get it working.  I believe I need to use REG QUERY and then %errorlevel% but I cant quite get it right.

The reg key value I am trying to query is [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83217045FF}] DisplayVersion="7.0.450"
0
Comment
Question by:fieldj
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 39767737
Try this; just add your installation code after the last line:
@echo off
setlocal
set Key=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83217045FF}
set CheckVersion=7.0.450
set DisplayVersion=n/a
for /f "tokens=2*" %%a in ('reg query "%Key%" /v "DisplayVersion" 2^>NUL') do set DisplayVersion=%%b
echo Installed Version: %DisplayVersion%
if %CheckVersion%==%DisplayVersion% (
	echo Already installed.
	goto :eof
)
echo Installing new version %CheckVersion% ...

Open in new window

0
 

Author Comment

by:fieldj
ID: 39767831
Thanks OBda, this is looking really good.

I just need to do a bit more testing but it looks very promising at the moment.
0
 

Author Closing Comment

by:fieldj
ID: 39767946
Script works perfectly.  Thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question