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;
}