GetOS

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetOS os
::
:: By:   Ritchie Lawrence, 2003-09-18. Version 1.0
::
:: Func: Returns the O/S version; NT40, 2000, 2002 or 2003.
::       For NT4/2000/XP/2003.
::
:: Args: %1 var to receive O/S version (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "cmd=net config work^|findstr/b /c:"Soft""
for /f "tokens=1-2 delims=." %%a in ('%cmd%') do (
  for %%z in (%%a%%b) do set o=%%z)
endlocal & set "%1=%o:40=NT40%" & (goto :EOF)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Parameters

%1 var to receive O/S version (by ref)

Return Values

Value Operating System
NT40 Microsoft Windows NT 4.0
2000 Microsoft Windows 2000
2002 Microsoft Windows XP
2003 Microsoft Windows 2003

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetOS ver
echo/Operating System is: %ver%
goto :EOF

Remarks

This function is independant of the command interpreter version, i.e. If the script is executed by a Windows 2000 version of cmd.exe on a Windows NT 4.0 machine, NT40 will be returned.

See Also