4.1 How to get a Windows Version?

As you know, in Windows 8.1 and later Windows version, GetVersion(Ex) APIs have been deprecated. Those APIs would not return a correct version value under those systems, without specifying a supportedOS tag for Windows 8.1 or Windows 10 in the application manifest file. ( Operating system version changes in Windows 8.1 and Windows Server 2012 R2),. As for a sample program using a manifest file with the supportedOS tags, please see WindowsVersion.
If you are familiar with WMI programming, it may be better to use WMI Win32_OperatingSystem class to get the correct Windows version (OS Name).
In the latest SOL9.2.0 library, we have implemented SOL::SWbemQueryOperatingSystem C++ class to query various information on Windows operating system.
The following 'SWbemQueryOperatingSystemApplet' example based on the C++ class shows how to get "Caption" property, which contains a Windows OS name, and All ("*") properties of Windows System. See also a GUI version SolOperatingSystemViewer


/*
 * SWbemQueryOperatingSystemApplet.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//SOL9
// 2015/12/15

#include <sol/wmi/SWbemQueryOperatingSystem.h>


void _tmain(int argc, const TCHAR** argv)
{  
  try {
    Locale locale;
    
    {    
      //1 Create an instance of SWbemQueryOperatingSystem thread specifying select item "Caption".
      SWbemQueryOperatingSystem operatingSystem("Caption");

      //2 Start the query thread.
      operatingSystem.start();

      //3 Wait a completion of the query thread
      operatingSystem.wait();
    
      //4 Display the texts of ObjectSet.    
      for (long i = 0; i< operatingSystem.getObjectSetCount(); i++) {
        StringT<wchar_t> name;
        // Get a list of Name="Value" pair.
        operatingSystem.getObjectText(i, name);
        printf("%S\n", (const wchar_t*)name);
      }
    }
    
    {
      //1 Create an instance of SWbemQueryOperatingSystem thread specifying select item "*" (All items).
      SWbemQueryOperatingSystem operatingSystem("*");

      //2 Start the query thread.
      operatingSystem.start();

      //3 Wait a completion of the query thread
      operatingSystem.wait();
    
      //4 Display the text of ObjectSet queried.
      operatingSystem.dump();
    }
  } catch (HRESULT hr) {
    printf("Exception HRESULT=%0x", hr); 
  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    printf("Unknown exception\n");
  }

}


Last modified: 30 Aug 2016

 Last modified: 30 Aug 2016

Copyright (c) 2000-2016 Antillia.com ALL RIGHTS RESERVED.