how to tell what version of windows and/or cmd.exe a batch file is running on?

cmd, windows

Solution

The version of `cmd.exe` should actually be pretty irrelevant, unless you try to use features that didn't exist before (in `command.com` for example). There is the pseudovariable

%cmdextversion%

which 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:

for /f "tokens=2 delims=[]" %%x in ('ver') do set WINVER=%%x
set WINVER=%WINVER:Version =%

Problem

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

Original source