+ Reply to Thread
Results 1 to 3 of 3

Thread: How to get version of the Windows that I am running on?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    43

    How to get version of the Windows that I am running on?

    How to get version of the Windows that I am running on?

    How to get whether it is Windows XP, Windows Vista or Windows 7?

    I need to display it on my About page of application.

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    37
    You can use following code for this:

    Code:
    CString GetVersionString()
    {
    	CString strVersionString ;
    	
    	OSVERSIONINFOEX objVesrionInfoEx ;
    	
    	objVesrionInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX) ;
    	GetVersionEx((OSVERSIONINFO*) &objVesrionInfoEx) ;
    	
    	
    	if ( VER_PLATFORM_WIN32_NT == objVesrionInfoEx.dwPlatformId && (objVesrionInfoEx.dwMajorVersion > 4) )
    	{
    		if ( objVesrionInfoEx.dwMajorVersion == 5 && objVesrionInfoEx.dwMinorVersion == 1 )
    		{
    			strVersionString = "Windows XP" ;
    		}
    		else if ( objVesrionInfoEx.dwMajorVersion == 5 && objVesrionInfoEx.dwMinorVersion == 0 )
    		{
    			strVersionString = "Windows 2000" ;
    		}
    		else if ( objVesrionInfoEx.dwMajorVersion == 5 && objVesrionInfoEx.dwMinorVersion == 2 )
    		{
    			if( objVesrionInfoEx.wProductType == VER_NT_WORKSTATION)
    			{
    				strVersionString = "Windows XP" ;
    			}
    			else
    			{
    				strVersionString = "Windows Server 2003" ;
    			}
    		}
    		else if ( objVesrionInfoEx.dwMajorVersion == 6 )
    		{
    			if( objVesrionInfoEx.dwMinorVersion == 0 )
    			{
    				if( objVesrionInfoEx.wProductType == VER_NT_WORKSTATION)
    				{
    					strVersionString = "Windows Vista" ;
    				}
    				else
    				{
    					strVersionString = "Windows Server 2008" ;
    				}
    			}
    			else if ( objVesrionInfoEx.dwMinorVersion == 1 )
    			{
    				if( objVesrionInfoEx.wProductType == VER_NT_WORKSTATION )
    				{
    					strVersionString = "Windows 7" ;
    				}
    				else
    				{
    					strVersionString = "Windows Server 2008 R2" ;
    				}
    			}
    		}
    	}
    	
    	return strVersionString ;
    }
    Note:
    Please note that it returns name of the OS. But you can make it to return version number.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    43
    I wanted the same.

    Thanks.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts