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\SOFTWAR E\ESD\INFO \Program REG_SZ ABC
This is what I have
This tells me that Program exists but it doesn't test that the content of Program is ABC.
Any assistance would be appreciated.
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\SOFTWAR
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
This tells me that Program exists but it doesn't test that the content of Program is ABC.
Any assistance would be appreciated.
I typically do something like this:
»bp
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"
)
»bp
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried using the /D switch? e.g.
Open in new window