How can one determine what version of Windows and/or cmd.exe a batch file is running on?
There is no cmd /version
that I've been able to find and the results of SET in a command prompt session don't give anything obviously unique (between XP and Win7 anyway).
you can use the "systeminfo" @ cmd.exe
Maybe someone will need the following to determine the SKU (Win7). I'm using some of this script to pick the right OS and XML during sysprep. Hope it helps!
The internal command
ver
reports windows version number (which could have been learned by typinghelp
at the command prompt).There is a dynamic variable
%CMDEXTVERSION%
, but it hasn't progressed in several releases so it's only useful for delineating between Windows NT and Windows 2000 and newer. (Thanks @Joey, here.)Here's a batch to parse the output of ver for XP and newer, courtesy of Simon Sheppard:
And here's my own fairly complete, largely academic, kick at the can which returns the parsed version number as environment variables:
The version of
cmd.exe
should actually be pretty irrelevant, unless you try to use features that didn't exist before (incommand.com
for example). There is the pseudovariablewhich holds the version of the command extensions which has been 2 for ages (at least back to NT 4, iirc).
But, back to the point: Running
ver
and parsing the version string might be your best bet:To find the windows version using
WMIC
you can use:Type "ver" at a command prompt.
Next time around, since this isn't really programming related but server or user related, you might try serverfault.com or superuser.com.