Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file to return user's operating system (NT, WIN 95 or 98)

72 views
Skip to first unread message

Bob Kaul

unread,
Jul 13, 2001, 10:59:55 AM7/13/01
to
Hello,
I need to have a batch file that returns the user's operating system.
Right now I have a batch file that copies .DLL files to the
/WINNT/SYSTEM32 directory on Windows NT and another batch file that
copies .DLL files to the /WINDOWS/SYSTEM for a Windows 95/98.
Question- is it possible to capture the Operating system and have an
IF statement that basically states "if NT then copy ... to
/WINNT/SYSTEM32 ELSE if 95/98 copy ....to /WINDOWS/SYSTEM"??? I would
like to have just one .BAT file to do this process.
I am extremly new to batch and have no clue where to begin. Any help
is greatly appreciated.
Thanks
Bob

William Allen

unread,
Jul 13, 2001, 11:49:33 AM7/13/01
to
Bob Kaul wrote in message
...snip

> I need to have a batch file that returns the user's operating system.

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


William Allen

unread,
Jul 13, 2001, 12:28:47 PM7/13/01
to
William Allen wrote in message
...snip

> 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).

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


g...@infinet.com

unread,
Jul 13, 2001, 10:59:38 PM7/13/01
to
William Allen <ma...@mayfly13.fsnet.co.uk> wrote:

: 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

William Allen

unread,
Jul 14, 2001, 1:47:24 AM7/14/01
to
<g...@infinet.com> wrote in message

> William Allen wrote:
>
> : 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.

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


0 new messages