Solved

How can I check the windows version ?

Posted on 2011-02-28
5
449 Views
Last Modified: 2013-11-20
Hello,
I tried this code that I found on the web without luck.
I thing it is not complete.
I would like to get the current system in str_system.
This is only for Windows NT no later versions....how do I have to check for XP, Vista or 7?
Please help. 500 points with a solution.
...still lerarning MFC....thanks.

Best regards,
Thomas

CString str_system;
OSVERSIONINFO osver;
osver.dwOSVersionInfoSize = sizeof(osver);
if (GetVersionEx(&osver))
{
   if (osver.dwPlatformId == VER_PLATFORM_WIN32s)
   {
     str_system="Win32 ";
   }

   else if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
   {

    if (osver.dwMinorVersion == 0 && (strchr(osver.szCSDVersion,'B') == NULL)&& (strchr(osver.szCSDVersion,'C') == NULL))str_system="Windows 95 ";
    if (osver.dwMinorVersion == 10 && (strchr(osver.szCSDVersion,'A')   == NULL))str_system="Windows 98 ";
    if (osver.dwMinorVersion == 90)str_system="Windows Millenium Edition ";
    if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)str_system="Windows NT ";

   }

}

Open in new window

0
Comment
Question by:tsp2002
  • 3
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34996724
0
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 500 total points
ID: 34996975
Here is a snippet
void GetWindowsOS()
{

     OSVERSIONINFOEX       versionInfo;
     memset( &versionInfo, 0, sizeof versionInfo );
     versionInfo.dwOSVersionInfoSize = sizeof versionInfo;
     GetVersionEx( &versionInfo );

     switch (versionInfo.dwPlatformId)
     {
        case VER_PLATFORM_WIN32_WINDOWS:
           if (versionInfo.dwMajorVersion == 4 && versionInfo.dwMinorVersion == 90)
			AfxMessageBox(L"WINDOWS ME");
           if (versionInfo.dwMajorVersion == 4 && versionInfo.dwMinorVersion == 10)
                        AfxMessageBox(L"WINDOWS 98");
           if (versionInfo.dwMajorVersion == 4 && versionInfo.dwMinorVersion == 0)
                        AfxMessageBox(L"WINDOWS 95");
           break;

        case VER_PLATFORM_WIN32_NT:
           if ( versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 1 )
                       AfxMessageBox(L"WINDOWS XP");
           else if ( versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0 )
                       AfxMessageBox(L"WINDOWS 2000");
           else if ( versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 0 )
           {
		   if( versionInfo.wProductType == VER_NT_WORKSTATION)
				AfxMessageBox(L"WINDOWS VISTA");
                   else 
				AfxMessageBox(L"WINDOWS 2K8 SERVER");
      	   }
           else if ( versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 1 )
	   {
		   if( versionInfo.wProductType == VER_NT_WORKSTATION)
			AfxMessageBox(L"WINDOWS 7");
                   else 
			AfxMessageBox(L"WINDOWS 2K8 SERVER");
           }

           break;
       }//Switch ends here 
}

Open in new window

0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 34997034
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 34997049

http://msdn.microsoft.com/en-us/library/ms724832%28v=vs.85%29.aspx

Operating system      Version number
Windows 7                              6.1
Windows Server 2008 R2      6.1
Windows Server 2008        6.0
Windows Vista                      6.0
Windows Server 2003 R2      5.2
Windows Server 2003              5.2
Windows XP 64-Bit Edition      5.2
Windows XP                      5.1
Windows 2000                      5.0
0
 

Author Closing Comment

by:tsp2002
ID: 34997311
Thank you for your help,
best regards, Thomas
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c++ how to tell if the progra is ctl or mfc atl ect 6 54
sumNumber challenge 16 99
Hibernate methods 2 58
Detect file exist or not 3 80
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now