Link to home
Start Free TrialLog in
Avatar of Ken Thompson
Ken Thompson

asked on

How to test if the contents of a registry key string (REG_SZ) equals ABC?

I have  a VB script I'm using to perform a task that depends on the value of a registry key string value.  I need to query the key and find out if the contents of a string value (REG_SZ) equals ABC.

I already use a script that checks if a registry key exists and it works fine.  I can't seem to find any information on how to check if the contents of a registry key value equals ABC.  I need to check if the string contains ABC - like below.

HKEY_LOCAL_MACHINE\SOFTWARE\ESD\INFO\Program      REG_SZ    ABC  

This is what I have

REM @echo off

reg query HKEY_LOCAL_MACHINE\SOFTWARE\ESD\INFO /v Program REM >nul 2>&1

if %ERRORLEVEL% == 0 goto THERE
if %ERRORLEVEL% == 1 goto NOTTHERE

:THERE

echo APS is there.


:NOTTHERE

echo APS is not there!

Pause

Exit b/0

Open in new window


This tells me that Program exists but it doesn't test that the content of Program is ABC.

Any assistance would be appreciated.
Avatar of NVIT
NVIT
Flag of United States of America image

Have you tried using the /D switch? e.g.


reg query HKEY_LOCAL_MACHINE\SOFTWARE\ESD\INFO /v Program /d "some data here"

Open in new window



Avatar of Bill Prew
Bill Prew

I typically do something like this:

for /F "tokens=1-2*" %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\ESD\INFO" /V Program 2^>NUL ^| findstr /I "Program"') do set "Program=%%~C"
if /i "%Progam% EQU "ABC" (
    echo Program was "ABC"
)

Open in new window


»bp
Avatar of Ken Thompson

ASKER

Never mind all.  I figured it out.  Here it is.

REM @echo off

reg query HKEY_LOCAL_MACHINE\SOFTWARE\ESD\INFO /v Program | find.exe /c "ABC" >nul

if %ERRORLEVEL% == 0 goto THERE
if %ERRORLEVEL% == 1 goto NOTTHERE

:THERE

echo ABC is there.


:NOTTHERE

echo ABC is not there!

Pause

Exit b/0

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ken Thompson
Ken Thompson

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