VC Gets the operating system version (from MSDN)
#include
Bool DisplaySystemVersion () {OsversionInfoEx OSVI; BOOL BOSVERSIONFOEX;
// Try Calling getversionEx Using The OsversionInfoEx structure. ///////////////////////////Iffs osversioninfo structure.
ZeromeMory (osversioninfoex); Osvi.dwosveionsInfosize = Sizeof (OsversionInfoEx);
IF (! ((bosversioninfoEx = getversionex ((OSVersionInfo *) & OSVI))) {// if osversioninfoEx Doesn't Work, Try OsversionInfo.
Osvi.dwosveionsInfosize = 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.WsuItemsk & 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 & 0xFFFFFFF Else {Printf ("% s (build% d) / n", osvi.szcsdversion, osvi.dwbuildnumber & 0xfff);} 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;