Click here to Skip to main content
Click here to Skip to main content

Detecting the Operating System Version

, 22 Oct 2001
Rate this:
Please Sign up or sign in to vote.
Detecting the computer's Operating System version
<!-- Download Links --> <!-- Article image -->

Sample Image - GUI_model.jpg

<!-- Add the rest of your HTML here -->

Introduction

I wrote this program to detect the operating system version under which my application is running. The GetVersionEx function obtains extended information about the version of the operating system that is currently running. Here's the source code:

OSVERSIONINFO OSversion;
	
OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
::GetVersionEx(&OSversion);

switch(OSversion.dwPlatformId)
{
   case VER_PLATFORM_WIN32s: 
           m_sStr.Format("Windows %d.%d",OSversion.dwMajorVersion,OSversion.dwMinorVersion);
	   break;
   case VER_PLATFORM_WIN32_WINDOWS:
  	  if(OSversion.dwMinorVersion==0)
	      m_sStr="Windows 95";  
	  else
          if(OSversion.dwMinorVersion==10)  
	      m_sStr="Windows 98";
       	  else
          if(OSversion.dwMinorVersion==90)  
	      m_sStr="Windows Me";
          break;
   case VER_PLATFORM_WIN32_NT:
  	 if(OSversion.dwMajorVersion==5 && OSversion.dwMinorVersion==0)
             m_sStr.Format("Windows 2000 With %s", OSversion.szCSDVersion);
         else	
         if(OSversion.dwMajorVersion==5 &&   OSversion.dwMinorVersion==1)
             m_sStr.Format("Windows XP %s",OSversion.szCSDVersion);
         else	
	 if(OSversion.dwMajorVersion<=4)
	    m_sStr.Format("Windows NT %d.%d with %s",
                           OSversion.dwMajorVersion,
                           OSversion.dwMinorVersion,
                           OSversion.szCSDVersion);			
         else	
             //for unknown windows/newest windows version
	    m_sStr.Format("Windows %d.%d ",
                           OSversion.dwMajorVersion,
                           OSversion.dwMinorVersion);
         break;
}
		
UpdateData(FALSE);

The data structure contains operating system version information:

typedef struct _OSVERSIONINFO{ 
           DWORD dwOSVersionInfoSize; 
           DWORD dwMajorVersion; 
           DWORD dwMinorVersion; 
           DWORD dwBuildNumber; 
           DWORD dwPlatformId; 
           TCHAR szCSDVersion[ 128 ]; 
} OSVERSIONINFO; 

dwOSVersionInfoSize

Specifies the size, in bytes, of this data structure.

dwMajorVersion

Identifies the major version number of the operating system. For example, for Windows NT version 3.51, the major version number is 3; and for Windows NT version 4.0, the major version number is 4.

dwMinorVersion

Identifies the minor version number of the operating system. For example, for Windows NT version 3.51, the minor version number is 51; and for Windows NT version 4.0, the minor version number is 0.

dwBuildNumber

Windows NT/2000: Identifies the build number of the operating system.

Windows 95/98: Identifies the build number of the operating system in the low-order word. The high-order word contains the major and minor version numbers.

dwPlatformId

Identifies the operating system platform.

szCSDVersion

Windows NT/2000: Contains a null-terminated string, such as "Service Pack 2", that indicates the latest Service Pack installed on the system. If no Service Pack has been installed, the string is empty.

Windows 95/98: Contains a null-terminated string that provides arbitrary additional information about the operating system.

If we want to detect Windows CE then value of OSversion.dwPlatformId is VER_PLATFORM_WIN32_CE

switch(OSversion.dwPlatformId)
{
   case VER_PLATFORM_WIN32_CE: 
           m_sStr.Format("Windows CE %d.%d",
                         OSversion.dwMajorVersion,
                         OSversion.dwMinorVersion);
}

References

Microsoft Platform SDK : Windows System Information

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

Share

About the Author

Agus Kurniawan
Founder PE College
Indonesia Indonesia
He gradueted from Sepuluh Nopember Institute of Technology (ITS) in Department of Electrical Engineering, Indonesia. His programming interest is VC++, C#, VB, VB.NET, .NET, VBScript, Delphi, C++ Builder, Assembly,and ASP/ASP.NET. He's founder for PE College(www.pecollege.net), free video tutorial about programming, infrastructure, and computer science. He's currently based in Depok, Indonesia. His blog is http://geeks.netindonesia.net/blogs/agus and http://blog.aguskurniawan.net

Comments and Discussions

 
GeneralWine detection Pinmemberjk200117-Feb-09 1:17 
QuestionDetecting Different OS version within a giving OS Pinmemberhcraes24-Oct-07 8:09 
GeneralHelp PinmemberNagarajoorao9-Feb-07 8:32 
QuestionBits? Pinmemberasp-12315-Jul-06 2:18 
QuestionWindows 2k3 ? Pinmemberlinhduylv14-Nov-05 16:24 
Generalmfc42d.dll Pinmemberbaggy27-Jul-05 4:04 
GeneralRe: mfc42d.dll Pinmemberjk200117-Feb-09 1:37 
GeneralThanks, nice simple example PinmemberDoug Brower16-May-02 4:55 
GeneralProblem on Windows Xp : cannot catch events of smart-card .... Pinmembervanta3-Feb-02 23:51 
GeneralRe: Problem on Windows Xp : cannot catch events of smart-card .... Pinmemberlordneo7-Dec-04 23:31 
Generaldetermining OS remotely Pinmemberpesglobe11-Dec-01 6:24 
Generalother system-infos (e.g. terminal server or server-edition at all) Pinmembermloibl23-Oct-01 9:06 
GeneralRe: other system-infos (e.g. terminal server or server-edition at all) PinmemberAgus Kurniawan23-Oct-01 22:57 
GeneralNice job! PinmemberPhil Sidari23-Oct-01 8:20 
GeneralRe: Nice job! PinmemberAgus Kurniawan23-Oct-01 22:55 
Generalyou can also type "ver" from cmd prompt PinmemberAnonymous22-Oct-01 6:44 
GeneralRe: you can also type "ver" from cmd prompt PinmemberAgus Kurniawan22-Oct-01 18:07 
GeneralRe: you can also type &quot;ver&quot; from cmd prompt Pinsussargila0030-Jul-04 0:10 
GeneralVery poor PinmemberJerry III21-Oct-01 22:52 
GeneralRe: Very poor PinmemberAgus Kurniawan23-Oct-01 7:08 
GeneralRe: Very poor PinmemberJerry III23-Oct-01 22:43 
GeneralRe: Very poor PinmemberBill Hebner28-May-02 3:59 
QuestionWindows XP? PinmemberAnatoly Ivasyuk17-Oct-01 10:57 
AnswerRe: Windows XP? PinmemberAgus Kurniawan17-Oct-01 14:56 

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 | Mobile
Web04 | 2.8.140821.2 | Last Updated 23 Oct 2001
Article Copyright 2001 by Agus Kurniawan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid