We help IT Professionals succeed at work.

Reg query Batch file

underground712
on
Medium Priority
569 Views
Last Modified: 2012-05-12
I need a batch file to do a reg query to find version in a string, if found goto end, if not found, run  mcmd
HKEY_LOCAL_MACHINE\SOFTWARE\Novell\ZCM has a string named version and search the value for 11.1.1
Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Give this a try, i think it should be close, although I don't have that actual key to test it.

@echo off
set Version=
for /F "tokens=3" %%A in ('REG QUERY "HKLM\SOFTWARE\Novell\ZCM" /v Version ^| findstr /r "REG_"') do call set Version=%%A
if "%Version% NEQ "11.1.1" (
  mcmd
)

Open in new window

~bp
Something along these line should do the trick:
@echo off
for /f "tokens=3" %%a in ('reg query hklm\software\novell\zcm /v version') do set version=%%a

if "%version%"=="11.1.1" (
  start mcmd
)

Open in new window

Oops! Pipped at the post...

Also, my logic is reversed (should have read the question more carefully). As billprew points out it should be 'NEQ' as in:

@echo off
for /f "tokens=3" %%a in ('reg query hklm\software\novell\zcm /v version') do set version=%%a

if "%version%" neq "11.1.1" (
  start mcmd
)
Here's a SHORT version:

@echo off
for /f "tokens=3" %%a in ('reg query hklm\software\novell\zcm /v version ^| find /i "version"') do if not "%%a"=="11.1.1" mcmd
I meant...
@echo off
for /f "tokens=3" %%a in ('reg query hklm\software\novell\zcm /v version ^| find /i "version"') do if  not "%%a"=="11.1.1" mcmd

Open in new window

Here's a quick way of doing it...
reg query hklm\software\novell\zcm /v version | find "11.1.1" >nul || mcmd

Open in new window

And who said DOS is dead?...
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Some guy with a PowerShell hat on as I recall.. ;-)

~bp

Author

Commented:
Ty :)
I was so certain I was gonna bag some points for this one I nearly had my chest measured... :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.