1
if "%OS%"=="Windows_NT" setlocal

Hi have a batch script and I wonder why is checking OS version? Are there differences in batch syntax with Windows 95/98?

I am with Windows 7 and echo %OS% is Windows_NT why?

Xelian
  • 14,624
  • 22
  • 83
  • 129
  • 2
    Windows 7 is a continuation of the NT line. All the modern Windows are :) The last non-NT version was 98 SE/ME or some such, since Win 2000/XP, everything is NT. Except for Windows RT nowadays, perhaps. – Luaan Oct 30 '14 at 10:52
  • 1
    @Luaan the last non-NT Windows is Windows ME – phuclv Oct 30 '14 at 10:56
  • OK. That answers 2nd part of my question. But the first? – Xelian Oct 30 '14 at 10:56
  • @LưuVĩnhPhúc I thought we decided to forget everything about Windows ME. But oh well, my mistake :D – Luaan Oct 30 '14 at 10:57
  • ok but is there difference in shell language in NT and non NT versions? – Xelian Oct 30 '14 at 10:58
  • it depends on what your script is doing. Each version of Windows introduce a lot of new commands or options so it's not backward compatible – phuclv Oct 30 '14 at 11:04

1 Answers1

3

setlocal doesn't work on non-NT systems, as simple as that.

It's not exactly easy to find, but you'll see that it is in documentation of the command processor for NT 4.0, Windows XP etc., while it's missing in 95, 98 etc. (which use the MS-DOS command processor rather than the NT shell).

Windows 7 is a Windows NT system, just like Windows 2000, XP, or Windows Server 2008, for example. The version number is in fact a continuation of the line - Windows NT 4.0 being followed by 2000 (5.0), XP (5.1+), Vista (6.0), 7 (6.1) etc.

Luaan
  • 57,516
  • 7
  • 84
  • 100
  • Related questions: [How do you use SETLOCAL in a batch file?](http://stackoverflow.com/questions/13704223/how-do-you-use-setlocal-in-a-batch-file) and [Windows batch files: .bat vs .cmd?](http://stackoverflow.com/questions/148968/windows-batch-files-bat-vs-cmd) (found by Google: "cmd vs command") – xmojmr Oct 30 '14 at 11:39