How to detect Windows Server 2003/2008 Release (R1 or R2) programatically?
ver
on the command line will give you the version and build number. For 2008 R1/R2 in particular you can always check the build number:
http://en.wikipedia.org/wiki/Windows_NT#Releases
Although it's a bit harder to detect 2003 R1/R2, not sure if you want to?
EDIT: If you want build number or a plain text version number then you can also check the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
Have you looked at using WMI?
Win32_OperatingSystem
The Win32_OperatingSystem class represents an operating system installed on a Win32 computer system. Any operating system that can be installed on a Win32 system is a descendent (or member) of this class. Example: Microsoft Windows 95.
Win32_OperatingSystem Properties :
BuildNumber : The BuildNumber property indicates the build number of the operating system. It can be used for more precise versioning information than product release version numbers Example: 1381
BuildType : The BuildType property indicates the type of build used for the operating system. Examples are retail build and checked build.
Caption : The Caption property is a short textual description (one-line string) of the object.
Description : The Description property provides a description of the Windows operating system. Some user interfaces (those that allow editing of this description) limit its length to 48 characters.
ProductType : The ProductType property indicates additional information about the system. This member can be one of the following values: 1 - Work Station 2 - Domain Controller 3 - Server
ServicePackMajorVersion : The ServicePackMajorVersion property indicates the major version number of the service pack installed on the computer system. If no service pack has been installed, the value is zero. ServicePackMajorVersion is valid for computers running Windows 2000 and later (NULL otherwise).
ServicePackMinorVersion : The ServicePackMinorVersion property indicates the minor version number of the service pack installed on the computer system. If no service pack has been installed, the value is zero. ServicePackMinorVersion is valid for computers running Windows 2000 and later (NULL otherwise).
Version : The Version property indicates the version number of the operating system. Example: 4.0