Click here to Skip to main content
11,492,523 members (62,691 online)
Click here to Skip to main content

XWinVer - Simple class to get Windows OS version

, 13 Jun 2007 CPOL 104.2K 1.9K 65
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions

 
QuestionWINDOWS IDENTIFIER FROM THERE BOOTABLE FILES Pin
panchal tejas9-Aug-12 20:51
memberpanchal tejas9-Aug-12 20:51 
GeneralMy vote of 5 Pin
kezhu3-Nov-10 16:18
memberkezhu3-Nov-10 16:18 
AnswerRe: My vote of 5 Pin
Hans Dietrich18-Apr-11 23:05
mentorHans Dietrich18-Apr-11 23:05 
QuestionUpdate for Windows 7 [modified] Pin
vol6124-Mar-10 8:25
membervol6124-Mar-10 8:25 
AnswerRe: Update for Windows 7 Pin
Hans Dietrich19-Apr-11 11:36
mentorHans Dietrich19-Apr-11 11:36 
GeneralSecond Update to include standard x64 edition Pin
Timothy W. Okrey20-Aug-09 9:33
memberTimothy W. Okrey20-Aug-09 9:33 
GeneralRe: Second Update to include standard x64 edition Pin
Hans Dietrich20-Aug-09 15:36
mvpHans Dietrich20-Aug-09 15:36 
GeneralRe: Second Update to include standard x64 edition Pin
mykel12-Nov-09 3:45
membermykel12-Nov-09 3:45 
GeneralRe: Second Update to include standard x64 edition Pin
LionelP15-Mar-10 18:48
memberLionelP15-Mar-10 18:48 
GeneralRe: Second Update to include standard x64 edition Pin
Timothy W. Okrey23-Mar-10 4:36
memberTimothy W. Okrey23-Mar-10 4:36 
GeneralRe: Second Update to include standard x64 edition Pin
kezhu3-Nov-10 16:25
memberkezhu3-Nov-10 16:25 
GeneralRe: Second Update to include standard x64 edition Pin
Dillon Sadofsky15-Apr-11 12:14
memberDillon Sadofsky15-Apr-11 12:14 
AnswerRe: Second Update to include standard x64 edition Pin
Hans Dietrich19-Apr-11 11:37
mentorHans Dietrich19-Apr-11 11:37 
GeneralRe: Second Update to include standard x64 edition Pin
PJ Arends18-Jun-11 12:53
memberPJ Arends18-Jun-11 12:53 
GeneralUpdated for Win7, Win2003 R2, Win2008 and Win2008 R2 Pin
Timothy W. Okrey20-Aug-09 8:17
memberTimothy W. Okrey20-Aug-09 8:17 
GeneralRe: Updated for Win7, Win2003 R2, Win2008 and Win2008 R2 Pin
Member 297763612-Nov-09 11:20
memberMember 297763612-Nov-09 11:20 
GeneralRe: Updated for Win7, Win2003 R2, Win2008 and Win2008 R2 Pin
Timothy W. Okrey13-Nov-09 5:05
memberTimothy W. Okrey13-Nov-09 5:05 
GeneralRe: Updated for Win7, Win2003 R2, Win2008 and Win2008 R2 Pin
Member 297763613-Nov-09 5:28
memberMember 297763613-Nov-09 5:28 
GeneralRe: Updated for Win7, Win2003 R2, Win2008 and Win2008 R2 Pin
kezhu17-Dec-09 14:25
memberkezhu17-Dec-09 14:25 
GeneralNice class but is a bit inefficient Pin
Defenestration6-Apr-08 11:27
memberDefenestration6-Apr-08 11:27 
QuestionRe: Nice class but is a bit inefficient Pin
jmnaste6-Jun-08 5:47
memberjmnaste6-Jun-08 5:47 
AnswerRe: Nice class but is a bit inefficient Pin
Defenestration6-Jun-08 6:18
memberDefenestration6-Jun-08 6:18 
GeneralRe: Nice class but is a bit inefficient Pin
jmnaste21-Aug-08 5:56
memberjmnaste21-Aug-08 5:56 
GeneralRe: Nice class but is a bit inefficient Pin
Hans Dietrich21-Aug-08 6:17
mvpHans Dietrich21-Aug-08 6:17 
GeneralRe: Nice class but is a bit inefficient Pin
JamesLHuff11-Mar-09 12:03
memberJamesLHuff11-Mar-09 12:03 
GeneralWindows 2008 Pin
vvatclor6-Mar-08 22:35
membervvatclor6-Mar-08 22:35 
GeneralWindows FLP Pin
Steffen Lange13-Jun-07 6:53
memberSteffen Lange13-Jun-07 6:53 
GeneralDetecting Windows VISTA Pin
AlexEvans25-Sep-06 17:27
memberAlexEvans25-Sep-06 17:27 
GeneralRe: Detecting Windows VISTA Pin
islobodan28-Jan-07 11:04
memberislobodan28-Jan-07 11:04 
GeneralRe: Detecting Windows VISTA Pin
AlexEvans28-Jan-07 11:30
memberAlexEvans28-Jan-07 11:30 
NewsWinXP x64 Pin
quatso6-Nov-05 20:41
memberquatso6-Nov-05 20:41 
GeneralLegacy OS are missing Pin
KarstenK24-Mar-05 0:53
memberKarstenK24-Mar-05 0:53 
GeneralScreenshots not displayed. Pin
WREY23-Mar-05 7:09
memberWREY23-Mar-05 7:09 
GeneralRe: Screenshots not displayed. Pin
Hans Dietrich23-Mar-05 8:12
memberHans Dietrich23-Mar-05 8:12 
GeneralRe: Screenshots not displayed. Pin
WREY23-Mar-05 8:42
memberWREY23-Mar-05 8:42 
GeneralRe: Screenshots not displayed. Pin
Ed.Poore12-Jun-07 13:22
memberEd.Poore12-Jun-07 13:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 13 Jun 2007
Article Copyright 2005 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid