Home c++ GetVersionEx works wrong

GetVersionEx works wrong

Author

Date

Category

Under Windows 10 gives a value of 6, although it should be 10. Why so?

p.s. Manifesto disabled


Answer 1, Authority 100%

Something like that – code worker 100%:

Tstring System_Controll :: SystemControll :: getwindowsversion ()
{
  Tstring Versionoc;
  System_info sysinfo {};
  TypeDef void (__ stdcall * getSystemInfo) (LPSYSTEM_INFO);
  OsversionInfoex OS_VER {};
  OS_VER.DWOSVERSIONFOSIZE = SIZEOF (Osversioninfoex);
  if (! GetVersionEx ((lposversionInfo) & amp; os_ver)) {msg_er_full; Return Versionoc; }
  DWORD MAJOR {};
  DWORD MINOR {};
  Lpbyte pinforawdata {};
  if (nerr_success == NetWKStageTInfo (NULL, 100, & AMP; PINFORAWDATA))
  {
    Wksta_info_100 * pworkstationinfo = (wksta_info_100 *) pinforawdata;
    Major = pworkstationinfo- & gt; wki100_ver_major;
    minor = pworkstationinfo- & gt; WKI100_VER_MINOR;
    OS_VER.DWMAJORVERSion = Major;
    os_ver.dwminorversion = minor;
    if (nerr_success! = netapibufferfree (pinforawdata)) {msg_er_full; }
  }
  ELSE If (OS_VER.DWMAJORVERSion == 6 & amp; & amp; os_ver.dwminorversion == 2)
  {
    OsversionInfoexW OSVI {};
    OSVI.DWOSVERSIONFOSIZE = SizeOF (OSVI);
    osvi.dwminorversion = 3;
    ULONGLONG CM {};
    CM = VersetConditionMask (CM, VER_MINORVERSION, VER_EQUAL);
    If (VerifyVersionInfow (& amp; OSVI, VER_MINORVERSION, CM))
    {
      os_ver.dwminorversion = 3;
    }
  }
  GetSystemInfo GetSysInfo = (GetSystemInfo) GetProcaddress (GetModuleHandle (_T ("Kernel32.dll")), "GetNativeSystemInfo");
  if (getsysinfo == null) getsysiSinfo = :: getSystemInfo;
  GetSysInfo (& amp; sysinfo);
  if (os_ver.dwmajorversion == 10 & amp; os_ver.dwminorversion & gt; = 0 & amp; & amp; os_ver.wproducttype! = ver_nt_workstation) versionoc = _t ("Windows 10 Server");
  if (os_ver.dwmajorversion == 10 & amp; os_ver.dwminorversion & gt; = 0 & amp; & amp; os_ver.wproducttype == ver_nt_workstation) versionoc = _t ("windows 10");
  If (os_ver.dwmajorversion == 6 & amp; os_ver.dwminorversion == 3 & amp; & amp; os_ver.wproducttype! = ver_nt_workstation) versionoc = _t ("Windows Server 2012 R2");
  if (os_ver.dwmajorversion == 6 & amp; os_ver.dwminorversion == 3 & amp; & amp; os_ver.wproducttype == ver_nt_workstation) versionoc = _t ("Windows 8.1");
  if (os_ver.dwmajorversion == 6 & amp; os_ver.dwminorversion == 2 & amp; & amp; os_ver.wproducttype! = ver_nt_workstation) versionoc = _t ("Windows Server 2012");
  if (os_ver.dwmajorversion == 6 & amp; os_ver.dwminorversion == 2 & amp; & amp; os_ver.wproducttype == ver_nt_workstation) versionoc = _t ("windows 8");
  if (os_ver.dwmajorversion == 6 & amp; & amp; os_ver.dwminorversion == 1 & amp; & amp; os_ver.wproducttype! = ver_nt_workstation) versionoc = _t ("Windows Server 2008 R2");
  if (os_ver.dwmajorversion == 6 & amp; & amp; os_ver.dwminorversion == 1 & amp; & amp; os_ver.wproducttype == ver_nt_workstation) versionoc = _t ("windows 7");
  if (os_ver.dwmajorversion == 6 & amp; & amp; os_ver.dwminorversion == 0 & amp; & amp; os_ver.wproducttype! = ver_nt_workstation) versionoc = _t ("Windows Server 2008");
  if (os_ver.dwmajorversion == 6 & amp; & amp; os_ver.dwminorversion == 0 & amp; & amp; os_ver.wproducttype == ver_nt_workstation) versionoc = _t ("Windows Vista");
  if (os_ver.dwmajorversion == 5 & amp; & amp; os_ver.dwminorversion == 2 & amp; & amp; os_ver.wproducttype == ver_nt_workstation & amp; & amp; sysinfo.wprocessorarchitecture == processor_architecture_amd64) versionoc = _t ("windows xp x64");
  if (os_ver.dwmajorversion == 5 & amp; & amp; os_ver.dwminorversion == 2) versionoc = _t ("Windows Server 2003");
  if (OS_VER.DWMAJORVERSION == 5 & amp; & amp; os_ver.dwminorversion == 1) versionoc = _t ("Windows XP");
  if (os_ver.dwmajorversion == 5 & amp; & amp; os_ver.dwminorversion == 0) versionoc = _t ("Windows 2000");
  if (os_ver.dwmajorversion & lt; 5) versionoc = _t ("unknown");
  if (OS_VER.WServicePackmajor! = 0)
  {
    Tstring SP;
    TCHAR BUF [128] {};
    SP = _T ("SERVICE PACK");
#ifdef Unicode.
    SWPRINTF_S (BUF, SIZEOF (BUF), _T ("% HD"), OS_VER.WServicePackmajor); 
#ELSE.
    SPRINTF_S (BUF, SIZEOF (BUF), _T ("% HD"), OS_VER.WServicePackmajor);
#Endif
    SP.APPEND (BUF);
    Versionoc + = SP;
  }
  Return Versionoc;
}

Answer 2

msdn reports English in white :

WITH THE BEHAVIOR OF THE GETVERSIONEX API
HAS CHANGED IN THE VALUE IT WILL RETURN FOR THE OPERATING SYSTEM
Version. THE VALUE RETURNED by The GetVersionEx Function Now Depends
On How The Application Is Manifested.

Applications not Manifested for Windows 8.1 or Windows 10 Will Return The Windows 8 OS Version Value (6.2). Once An Application Is Manifested For A Given Operating System Version, GetVersionEx Will Always Return The Version That The Application Is Manifested for in Future Releases.


and the better to use?

And he also reports on the same page:

to Manifest Your Applications for Windows 8.1 or Windows 10, Refer to Targeting Your Application for Windows .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions