General
cancel
Showing results for 
Search instead for 
Did you mean: 

how do I determine the O/S version from a .bat script

SOLVED
Go to solution
Ian Lochray
Respected Contributor

how do I determine the O/S version from a .bat script

I have a .bat script which can run on Windows 2000 or Windows 2003. How can I tell which version of the operating system the script is running on?
4 REPLIES
Alexander M. Ermes
Honored Contributor
Solution

Re: how do I determine the O/S version from a .bat script

Hi there.
Just use the good old 'ver' in the .bat file.
On the newer win systems the ending is more like .cmd instead of .bat, isn't it ?
Rgds
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
Jon Finley
Honored Contributor

Re: how do I determine the O/S version from a .bat script

Well.... yes, use the VER command, but at least parse it out so that you can do some testing with it from within your batch file.

Note: I didn't have 2000 running, so could only supply the VER values for XP and 2003.

Example:

FOR /F "tokens=5 delims= " %%i in ('ver') do set my_ver=%%i
if %my_ver%==5.1.2600] set my_os=XP
if %my_ver%==5.2.3790] set my_os=2003

echo My OS is: %my_os%


Rather than echo out the OS, you could have your batch file skip to different areas based on the OS (my_os in this example).

Jon
"Do or do not. There is no try!" - Yoda
Marino Meloni_1
Honored Contributor

Re: how do I determine the O/S version from a .bat script

A .bat file usualy is a text file, with some command, it is hard to know for what os (or better for what dos version) it was written.
You can try to analyse the commands inside and the path of these command, changing windows version have changed the path of the dos (or emulated dos) commands.

the ver command may apply to the envoronment, I mean if you boot a floppy disk with the file system, you can run this command to know which version you booted from, but usualy at the end of the boot, the version already appear

marino
Ian Lochray
Respected Contributor

Re: how do I determine the O/S version from a .bat script

I was only really interested to see if I was on Windows 2000 or something else so I used "ver" and checked the output for the string "Windows 2000".
Thanks for your help.