[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-01-09
3
Medium Priority
?
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

649 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