VC + + Get OS Version (excerpt from MSDN) __c++

Source: Internet
Author: User

VC + + Get OS Version (excerpt from MSDN)

#include <windows.h>
#include <stdio.h>

BOOL displaysystemversion ()
{
Osversioninfoex OSVI;
BOOL Bosversioninfoex;

Try calling GetVersionEx using the OSVERSIONINFOEX structure.
//
If that fails, try using the OSVERSIONINFO structure.

ZeroMemory (&OSVI, sizeof (OSVERSIONINFOEX));
osvi.dwosversioninfosize = sizeof (OSVERSIONINFOEX);

if (!) ( Bosversioninfoex = GetVersionEx ((OSVERSIONINFO *) &OSVI))
{
If Osversioninfoex doesn ' t work, try osVersionInfo.

osvi.dwosversioninfosize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ((OSVERSIONINFO *) &OSVI))
return FALSE;
}

Switch (OSVI.DWPLATFORMID)
{
Case VER_PLATFORM_WIN32_NT:

Test for the product.

if (osvi.dwmajorversion <= 4)
printf ("Microsoft Windows NT");

if (osvi.dwmajorversion = = 5 && osvi.dwminorversion = 0)
printf ("Microsoft Windows 2000");

if (osvi.dwmajorversion = = 5 && osvi.dwminorversion = 1)
printf ("Microsoft Windows XP");

Test for product type.

         if (bosversioninfoex)
          {
            if (Osvi.wproducttype = = ver_nt_workstation)
            {
                if (Osvi.wsuitemask & Ver_suite_ PERSONAL)
                   printf ("Personal");
               Else
                   printf ("Professional " );
           }

else if (Osvi.wproducttype = = ver_nt_server)
{
if (Osvi.wsuitemask & Ver_suite_datacenter)
printf ("DataCenter Server");
else if (Osvi.wsuitemask & Ver_suite_enterprise)
printf ("Advanced Server");
Else
printf ("Server");
}
}
Else
{
HKEY hkey;
Char szproducttype[80];
DWORD Dwbuflen;

RegOpenKeyEx (HKEY_LOCAL_MACHINE,
"System//currentcontrolset//control//productoptions",
0, Key_query_value, &hkey);
RegQueryValueEx (hkey, "ProductType", NULL, NULL,
(LPBYTE) Szproducttype, &dwbuflen);
RegCloseKey (HKEY);
if (Lstrcmpi ("WINNT", szproducttype) = = 0)
printf ("Professional");
if (Lstrcmpi ("LanmanNT", szproducttype) = = 0)
printf ("Server");
if (Lstrcmpi ("Servernt", szproducttype) = = 0)
printf ("Advanced Server");
}

Display version, Service Pack (if any), and build number.

if (osvi.dwmajorversion <= 4)
{
printf ("Version%d.%d%s (build%d)/n",
osvi.dwMajorVersion,
osvi.dwMinorVersion,
Osvi.szcsdversion,
Osvi.dwbuildnumber & 0xFFFF);
}
Else
{
printf ('%s ' (build%d)/n ',
Osvi.szcsdversion,
Osvi.dwbuildnumber & 0xFFFF);
}
Break

Case Ver_platform_win32_windows:

         if (osvi.dwmajorversion = 4 && osvi.dwminorversion = 0)
         {
              printf ("Microsoft Windows 95");
             if (osvi.szcsdversion[1] = = ' C ' | | OSVI.SZCSDVERSION[1] = = ' B ')
                 printf ("OSR2");
        }

if (osvi.dwmajorversion = = 4 && osvi.dwminorversion = 10)
{
printf ("Microsoft Windows 98");
if (osvi.szcsdversion[1] = = ' A ')
printf ("SE");
}

if (osvi.dwmajorversion = = 4 && osvi.dwminorversion = 90)
{
printf ("Microsoft Windows Me");
}
Break

Case VER_PLATFORM_WIN32S:

printf ("Microsoft Win32s");
Break
}
return TRUE;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.