Typically, in WinNT systems, the OS environment variable
is set to the Operating System, and in Win9x systems this
variable is not generally present (unless user-created).
Additionally, look at the output from the VER command
which can be tested with FIND.
Something like this may help:
::====
@ECHO OFF
IF NOT (%OS%)==() GOTO WINNT
VER | find "95">NUL
IF NOT ERRORLEVEL 1 GOTO WIN95
VER | find "98">NUL
IF NOT ERRORLEVEL 1 GOTO WIN98
VER | find /i "Millennium">NUL
IF NOT ERRORLEVEL 1 GOTO WINME
ECHO. Operating system not detected
GOTO EOF
:WINNT
ECHO. The System environment variable OS is set in Windows NT
GOTO EOF
:WIN95
ECHO. VER outputs Windows 95 in Windows 95
GOTO EOF
:WIN98
ECHO. VER outputs Windows 98 in Windows 98
GOTO EOF
:WINME
ECHO. VER outputs Windows Millenium in Windows Millennium
GOTO EOF
:EOF
::====
or more simply, this may do for your purpose:
::====
@ECHO OFF
IF NOT (%OS%)==() GOTO WINNT
ECHO. It's not NT
GOTO EOF
:WINNT
ECHO. The System environment variable OS is set in Windows NT
GOTO EOF
:EOF
::====
--
William Allen
If you're concerned about user-created OS variable, you
might read the post:
From: Herbert Kleebauer
Newsgroups: alt.msdos.batch
Subject: Re: Find a file, return the directory
Message-ID: <3B4DE772...@unibwm.de>
Date: Thu, 12 Jul 2001 20:07:46 +0200
I can't test in WinNT, but you could try exploiting the
different pipe treatment between Win9xME and WinNT
to set the OS variable correctly (between these systems):
::====Fragment to SET OS in Win9xME but not in WinNT
@ECHO OFF
ECHO.SET OS=Win9xME>%TEMP%.\OS.BAT
TYPE %TEMP%.\OS.BAT|find "Win9xME">%TEMP%.\OS.BAT
FOR %%C IN (CALL DEL) DO %%C %TEMP%.\OS.BAT
ECHO. OS is %OS%
::====
The idea here is that, according to post quoted, in WinNT
the >redirection in the pipe (in TYPE line) erases the temporary
file before it's piped through FIND. In Win9xME, the file survives.
So when it's executed it contains nothing in WinNT (so leaves
the OS variable alone) but sets OS to Win9xME if in Win9xME.
--
William Allen
: I can't test in WinNT, but you could try exploiting the
: different pipe treatment between Win9xME and WinNT
: to set the OS variable correctly (between these systems):
I can confirm that it works correctly in WinNT. It reports "Win9xME" when
run under COMMAND.COM 5.0.
: ::====Fragment to SET OS in Win9xME but not in WinNT
: @ECHO OFF
: ECHO.SET OS=Win9xME>%TEMP%.\OS.BAT
: TYPE %TEMP%.\OS.BAT|find "Win9xME">%TEMP%.\OS.BAT
: FOR %%C IN (CALL DEL) DO %%C %TEMP%.\OS.BAT
: ECHO. OS is %OS%
: ::====
--
Gary L. Smith g...@infinet.com
Columbus, Ohio
Thanks for the test. Then it would seem that this modification sets
OS variable correctly in the three most common situations:
::====Fragment to set OS variable in NT, Win9xME, and LegacyDOS
@ECHO OFF
ECHO.SET OS=Win9xME>%TEMP%.\OS.BAT
TYPE %TEMP%.\OS.BAT|find "Win9xME">%TEMP%.\OS.BAT
FOR %%C IN (CALL DEL) DO %%C %TEMP%.\OS.BAT
IF NOT (%OS%)==(Win9xME) GOTO OSFOUND
VER | find /i "Windows">NUL
IF ERRORLEVEL 1 SET OS=LegacyDOS
:OSFOUND
ECHO. OS is %OS%
::====
--
William Allen