Solved

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

Posted on 2014-01-09
3
373 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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Script works perfectly.  Thank you.
0

Featured Post

Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

Join & Write a Comment

Suggested Solutions

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now