Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

XWinVer - Simple class to get Windows OS version

0.00/5 (No votes)
13 Jun 2007 1  
Get Windows OS version and service pack info in numeric and string formats.

Introduction

There are many classes to get Windows version numbers, so why another one? Briefly, because none of them offered the simplicity and low overhead that I wanted, while giving me the information I needed. Instead of writing endless standalone functions (is it XP? is it SP2?), I decided to incorporate everything into a single class.

To keep the class overhead down to a minimum, I designed a new class as a singleton, with version data retrieved and stored only once per program.

XWinVer Functions

The CXWinVersion class includes functions to retrieve the OS version number both as an integer and a string value, as well as service pack.

Here are the functions available in CXWinVersion:

// Public APIs:

//         NAME                            DESCRIPTION

// ---------------------  -----------------------------------------------

// GetMajorVersion()       Get major version number

// GetMinorVersion()       Get minor version number

// GetBuildNumber()        Get build number (ANDed with 0xFFFF for Win9x)

// GetServicePackNT()      Get service pack number

// GetPlatformId()         Get platform id

// GetServicePackString()  Get service pack string

// GetVistaProductString() Get Vista product string (e.g.,"Business Edition")

// GetVistaProductType()   Get Vista product type

// GetWinVersion()         Get windows version (CXWinVersion code)

// GetWinVersionString()   Get windows version as string

// IsMediaCenter()         TRUE = Media Center Edition

// IsWin95()               TRUE = Win95

// IsWin98()               TRUE = Win98

// IsWin2KorLater()        TRUE = Win2000 or later

// IsWin2003()             TRUE = Win2003

// IsWinCE()               TRUE = WinCE

// IsXP()                  TRUE = XP

// IsXPorLater()           TRUE = XP or later

// IsXPHome()              TRUE = XP Home

// IsXPPro()               TRUE = XP Pro

// IsXPSP2()               TRUE = XP SP2

// IsVista()               TRUE = Vista

// IsVistaHome()           TRUE = Vista Home

// IsVistaBusiness()       TRUE = Vista Business

// IsVistaEnterprise()     TRUE = Vista Enterprise

// IsVistaUltimate()       TRUE = Vista Ultimate

How To Use

To integrate XWinVer into your app, you first need to add XWinVer.h and XWinVer.cpp to your project. Next, include the header file XWinVer.h in each source module that you want to use CXWinVersion in. Now you can call CXWinVersion functions by just writing:

BOOL bXPSP2 = WinVersion.IsXPSP2();

Note that WinVersion is automatically instantiated when you include the header file XWinVer.h.

The Demo App

The demo app displays various version info:

For Windows XP:

screenshot

For Windows Vista:

screenshot

References

Revision History

Version 1.2 - 2007 June 7

  • Added IsVista(), IsVistaXXXXX()
  • Added GetVistaProductString()
  • Added GetVistaProductType()
  • Added GetPlatformId()
  • Added IsMediaCenter()
  • Added IsWin95()
  • Added IsWin98()
  • Added IsWinCE()

Version 1.1 - 2005 March 14

  • Initial public release.

Usage

This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please do consider posting the new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here