Link to home
Start Free TrialLog in
Avatar of missymadi
missymadi

asked on

How do I check for an existing Registry value in a DOS Batch file?

Experts,

       How do I check to see if there is an existing key in the registry file on an XP machine?
 I'm not sure how to make the batch file look at this key. This install is a little different, where usually there is a {;lkkj9uwje-lkajf;oi-lkj} number it is a directory iscsi200.
EX:  HKLM\software\microsoft\windows\currentversion\uninstall\iscsi200



right now I have
Avatar of Bill Prew
Bill Prew

You should be able to use the REG command in a batch script.  Depending on the exact contents of that registry entry you may want to look for a particular value, or just make sure something exists.  To get a feel for the command you can do REG /? at a command prompt.  Also try the following from a command promt:

REG QUERY HKLM\software\microsoft\windows\currentversion\uninstall\iscsi200

In a batch file you could just look for the ERROR: text that it returns if the key doesn't exist.  So maybe something like this:

REG QUERY HKLM\software\microsoft\windows\currentversion\uninstall\iscsi200 | find "ERROR:">NUL
if errorlevel 1 echo Registry Entry Missing

~bp
Avatar of missymadi

ASKER

I have used this command in the past but for some reason this batch is not running correctly. Please see attached file.
I also get the following error everytime I run the batch ERROR: The system was unable to find the specified registery key or value.

Thanks, Missymadi
@Echo off
::      ISCSI200.bat
::	Installs Diag Software if not already installed. 
::      Writes ISCSI200.bat activity to a file C:\ISCSI200.out. 
::      
 
::            
@Echo Off
 
::  Set Parent Registry Key
Set PTH=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

 
::  Check if Product is Installed
::  Echo Checking to see if ELT/1500 is installed..
Reg Query "%PTH%{iscsi200}" 


::Handle ErrorLevels
If ErrorLevel  1 Goto Install
If ErrorLevel  0 Goto Exit

:Install
Echo Installing ISCSI200...
ALLUSERS=1
Goto END1

:Exit
Echo %date%,%time%, ELT/1500 Software is already installed! >> C:\ISCSI\Initiator-2.08-build3825-x86fre.exe 

Goto END2

:END1
ECHO %date%,%time%,ELT/1500 Software is now installed on your system!  >> C:\ISCSI200.out 

:END2

Pause

Open in new window

Since this value in the registry is not a GUID, it should not be enclosed in curly braces.  So I think you need the following form for your query statement.

Reg Query "%PTH%iscsi200"

As a test just do the following and it will list all the nodes in the uninstall branch and you can see the format.

Reg Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

~bp
It is listed as
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\iscsi200. I tried removing the curly brackets but now I get back the registry key and the script is not running.
to be clear,
When I run the batch file and ISCSI is not installed, the batch file installs ISCSI but it does not display the END1. The END1 tag never runs.
When ISCSI is installed only the registry key for ISCSI is returned. The Exit tag is never run.  
So it sounds like the ERRORLEVEL check may be working okay.  If you want to suppress the display of the keys below that node change the query to look like:

Reg Query "%PTH%iscsi200" >NUL 2>NUL

Looking at the script you posted I hav a few questions:

==> ALLUSERS=1

What is that, it doesn't look like a program or command name that would execute?

==> Echo %date%,%time%, ELT/1500 Software is already installed! >> C:\ISCSI\Initiator-2.08-build3825-x86fre.exe  

I don't understand why you are redirecting your log info to an EXE program?  Is this the installer, if so doesn't it belong in the "Install routine?

As far as what branches your code is taking, I'd recommend you change the ECHO OFF to an ECHO ON for some testing, it will show you all the statements executed when the script runs.

~bp
ALLUSERS=1  means to allow any user to run the software, not just the installer. We had a problem here that standard users who did not install the product did not have rights to use the software. - this will give them rights.

I don't understand why you are redirecting your log info to an EXE program?  Is this the installer, if so doesn't it belong in the "Install routine? --- I shouldn't use copy and paste :)

Fixed the Echo's. Everything working now. THANKS!
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial