I'm doing a simple script to check MS Office version reading registry key value. Will be scenarios where the key won't exist (not office installed) I used many times reg.exe query KEY/Check 2>nul but can't make that work inside a FOR line. This is the line:
FOR /f "tokens=3" %%a in ('%SystemRoot%\System32\reg.exe query "HKEY_CLASSES_ROOT\Word.Application\CurVer" ^| %SystemRoot%\System32\findstr /C:"(Default)"') do set _Off_ver=%%a
I tried:
FOR /f "tokens=3" %%a in ('%SystemRoot%\System32\reg.exe query "HKEY_CLASSES_ROOT\Word.Application\CurVer" 2>nul ^| %SystemRoot%\System32\findstr /C:"(Default)"') do set _Off_ver=%%a
or
FOR /f "tokens=3" %%a in ('%SystemRoot%\System32\reg.exe query "HKEY_CLASSES_ROOT\Word.Application\CurVer" ^| %SystemRoot%\System32\findstr /C:"(Default)"'2>nul ) do set _Off_ver=%%a
and in many other places but I end up with the error:
> was unexpected at this time.
Anyone know how I can hide the error:
ERROR: The system was unable to find the specified registry key or value.
Inside that FOR Line?
THANKS