Computing.Net > Forums > Disk Operating System > how to find OS in batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to find OS in batch file

Reply to Message Icon

Name: Shree
Date: August 6, 2002 at 07:28:39 Pacific
Comment:

i want to run a program based on running operating system. can any one help me to find which operating system is running (95/98/NT/2000).



Sponsored Link
Ads by Google

Response Number 1
Name: astroraptor
Date: August 6, 2002 at 07:50:04 Pacific
Reply:

ECHO.%OS%

This works under Windows NT/2000/XP


0

Response Number 2
Name: Michael
Date: August 6, 2002 at 09:11:13 Pacific
Reply:

Also the VER command will work also.

-Michael


0

Response Number 3
Name: Secret_Doom
Date: August 6, 2002 at 11:19:35 Pacific
Reply:

NT systems have the %OS% variable set by default to 'Windows_NT', and non-NT systems don't. So, if you just want to act depending if the OS is NT (Win NT4,2000,XP) or non-NT (Win9x, Dos 6.22), this will do it:

if "%OS%"=="Windows_NT" goto NT
echo This is non-NT!
goto eof
:NT
echo This is NT!
:eof

However, if you need the batch file to act in a certain way for each OS, the best would be to check the return of the VER command.

Something like this would be required:

ver > %TEMP%.\T1.DAT
FIND "MS-DOS" < %TEMP%.\T1.DAT > nul
if not errorlevel=1 goto dos
FIND "Windows 95" < %TEMP%.\T1.DAT > nul
if not errorlevel=1 goto win95
FIND "Windows 98" < %TEMP%.\T1.DAT > nul
if not errorlevel=1 goto win98
FIND "Windows 2000" < %TEMP%.\T1.DAT > nul
if not errorlevel=1 goto win2000
FIND "Windows XP" < %TEMP%.\T1.DAT > nul
if not errorlevel=1 goto winXP
echo FATAL ERROR: could not detect your Operating System.
goto end
:: Here goes the part with the labels :dos
:: :win98 :win2000 etc
:end
if exist %TEMP%.\T1.DAT del %TEMP%.\T1.DAT

PS: I used a temporary file and all these lower-than characters intead of "VER|FIND..." because it's faster.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


help understanding dos &a... getting someones ip in do...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: how to find OS in batch file

Assign Date to a Variable in Batch File www.computing.net/answers/dos/assign-date-to-a-variable-in-batch-file/4748.html

Batch File Variables www.computing.net/answers/dos/batch-file-variables/14203.html

Return code in batch file www.computing.net/answers/dos/return-code-in-batch-file/4786.html