2013-11-26 19:13, justaguy:
> Now, here's the new code:
> Line 1: @echo off
> Line 2: for /f "skip=2 tokens=1-3 delims= " %%A in ('reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v version') do Set version=%%C
> Line 3: echo %version% | findstr /i "9.11."
>
> But Line 3 does not return the result if the value of the var of version contains "9.11.". How come?
It should -- perhaps the machine you are testing this on doesn't have
that version.
You might have another problem with FINDSTR later because you are
testing with a regular expression and the '.' represents any character.
So "9.11." will match "9.10.9911.16721" and many other strings. Use
either of these:
FINDSTR /C:"9.11."
FINDSTR /L "9.11."
But a better method which uses less CPU would be to make all your tests
with built-in commands and to not use FINDSTR, which is an external
command. Something like this:
For /F "skip=2 tokens=1-3 delims= " %%A in (
'reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v version'
) Do Set "version=%%C"
If /I "%version:~0,5%" EQU "9.11." (
REM Do version 9.11 stuff.
) Else If /I "%version:~0,5%" EQU "9.10." (
REM Do version 9.10 stuff.
)
Etcetera. Another way which might be more useful is to set the version
and subversion into separate variables for more control. Something like
this:
For /F "skip=2 tokens=1-3 delims= " %%A in (
'reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /v version'
) Do (
For /F "tokens=1,2 delims=." %%D in ("%%C") Do (
Set "version=%%D"
Set "subVersion=%%E"
)
)
If %version% EQU 9 (
Echo Do things for version 9.
If %subVersion% EQU 10 (
Echo Do things for version 9 subversion 10.
) Else If %subVersion% EQU 11 (
Echo Do things for version 9 subversion 11.
)
)
In the above, something is done for all version 9 and different things
are done additionally for the subversions. I've been applying the term
"subversion" but I really don't know what it is in this case.
Frank