?
Solved

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

Posted on 2014-01-09
3
Medium Priority
?
395 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Determining the an SCCM package name from the Package ID
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Suggested Courses

752 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