Windows 9x/Me version in variable

173 views Asked by At

How would you store the Windows 9x/Me version into a variable?

1

There are 1 answers

0
Mofi On BEST ANSWER

I don't know if COMMAND.COM of Windows 95, Windows 98 and Windows Millennium supports assigning the output of a command to an environment variable at all. What is definitely supported as tested by me on a machine running Windows 98 SE is:

@echo off
set WinVer=unknown

rem Windows 95
ver | find "4.00.950" >nul
if not errorlevel 1 set WinVer=4.00.950

rem Windows 95 SR2
ver | find "4.00.1111" >nul
if not errorlevel 1 set WinVer=4.00.1111

rem Windows 98
ver | find "4.10.1998" >nul
if not errorlevel 1 set WinVer=4.10.1998

rem Windows 98 SE
ver | find "4.10.2222" >nul
if not errorlevel 1 set WinVer=4.10.2222

rem Windows Millennium
ver | find "4.90.3000" >nul
if not errorlevel 1 set WinVer=4.90.3000

echo Windows version is: %WinVer%

Perhaps better for the task is a batch file like:

@echo off
ver | find "4.00." >nul
if not errorlevel 1 goto Win95
ver | find "4.10." >nul
if not errorlevel 1 goto Win98
ver | find "4.90." >nul
if not errorlevel 1 goto WinMe

echo ERROR: Could not determine Windows version!
goto EndBatch

:Win95
echo INFO: Detected OS as Windows 95.
rem More commands to run for Windows 95.
goto EndBatch

:Win98
echo INFO: Detected OS as Windows 98.
rem More commands to run for Windows 98.
goto EndBatch

:WinMe
echo INFO: Detected OS as Windows ME.
rem More commands to run for Windows ME.
goto EndBatch

rem Commands for other versions of Windows.

:EndBatch

Please take care not using labels with more than eight characters. It is possible to use longer label names, but for COMMAND.COM are only the first eight characters significant, i.e. goto Windows98 would be interpreted as goto Windows9 and therefore the batch file execution would continue on the line below a label starting with Windows9.

The Windows version strings used here are taken from Wikipedia article MS-DOS.