Solved

How can I check the windows version ?

Posted on 2011-02-28
5
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

634 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