Find Windows Version and Service Pack Number
(works in: Microsoft Windows/95/98/ME/NT/2000/XP/Vista)

It is sometimes useful to determine the system type, version number, and/or service pack number of a Windows system from within a program. The Windows API provides the functions GetVersion and GetVersionEx for this purpose, but they are often cumbersome to use.

The function GET_WIN_VERSION_EX gets the relevant information in one easy call, and the values are returned as integers.

*Important* I modified it on Jan. 8, 2007 to work with Windows Vista also. I have only tested with Vista Enterprise Edition. If you use with other versions and get incorrect results please let me know.

The routine is available as part of the C++ source file EXAM65.CPP. The routine has the following calling parameters:

        int GET_WIN_VERSION_EX(int*,int*,int*,int*,int*,int*)
where all values are returned by the routine. The function returns 0 for success, and non-zero for an error condition.

The six integer arguments are interpreted as follows:

       1st   :   System Type (0=unknown, 2=Win/95, 3=Win/98,
                              4=Win/ME, 5=Win/NT, 6=Win/2000,
                              7=Win/XP, 8=Win/2003, 9=Vista, 10=Longhorn)
       2nd   :   System Sub-type, interpreted as follows:
                  For Win/95: if=0 then original, if=1 then OSR2
                  For Win/98: if=0 then original, if=1 then Second Edition
                  For Win/NT/2000/XP:  if=0 then Unknown,
                      if=1 then Home/Personal Edition, =2 then Professional
                      =3 then Server, =4 then Advanced Server
                      =5 then Data Center Server, =6 then BackOffice
                  For Windows Vista:  if=0 then Unknown,
                      if=1 then Home/Personal Edition, =2 then Enterprise or Business
                  For Windows Longhorn Server:  if=0 then Unknown,
                      =3 then Server, =4 then Advanced/Enterprise Server
                      =5 then Data Center Server
       3rd   :   Major Version Number (e.g. 3 for Win/NT v3.51)
       4th   :   Minor Version Number (e.g. 51 for Win/NT v3.51)
       5th   :   Service Pack Number (for Win/NT/2000/XP/2003/Vista only)
       6th   :   Build Number

Note: The "Service Pack Number" is not meaningful for Win/95/98/ME - it will be returned as zero or a negative number for those cases.

You can download the file in ZIP format by clicking on the following link.

This works for Microsoft Windows 3.x/95/98/ME/NT/2000/XP/2003. I have tested with Visual C++ v6.0 and Visual Studio 2005 but it should work with other versions also. This routine requires a fairly recent version of the Win SDK to compile correctly, so if you are getting compile errors then most likely it is because you have an older version. If you want to update to a newer SDK, then get it from: http://www.microsoft.com/msdownload/platformsdk/sdkupdate. (not recommended over slow links). Please let me know of exceptions.

If you cannot update the SDK to compile this, then I do have a version that works with older SDKs. Please email me at the address below if you're interested in that.

After downloading, unzip the file Exam65.cpp into any folder. It contains a short console mode program which demonstrates how to call GET_WIN_VERSION_EX.

Change history:

  • 3/12/2002 - Fixed minor bug that was causing Win/ME to be reported as Win/95.
  • 10/28/2004 - Should now report Win/2003 also.
  • 1/8/2007 - Identifies Vista also.

If you have any questions please send them to the e-mail address below.

Further Reading:

Disclaimer:
This site contains some software that I've written over the years. It is believed to work, but there is no warranty. Please use at your own risk. If you notice any bugs please let me know by email at kochhar@physiology.wisc.edu.

Return to Ravi's Free Software Page
Return to Ravi's Home Page
Back to The Basement
This page last modified on : Jan. 8, 2007