Solved

How can I check the windows version ?

Posted on 2011-02-28
5
450 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

13 Experts available now in Live!

Get 1:1 Help Now