Solved

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

Posted on 2014-01-09
3
383 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 83

Accepted Solution

by:
oBdA earned 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 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