1
0

isnt.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "rar.hpp"
  2. DWORD WinNT()
  3. {
  4. static int dwPlatformId=-1;
  5. static DWORD dwMajorVersion,dwMinorVersion;
  6. if (dwPlatformId==-1)
  7. {
  8. OSVERSIONINFO WinVer;
  9. WinVer.dwOSVersionInfoSize=sizeof(WinVer);
  10. GetVersionEx(&WinVer);
  11. dwPlatformId=WinVer.dwPlatformId;
  12. dwMajorVersion=WinVer.dwMajorVersion;
  13. dwMinorVersion=WinVer.dwMinorVersion;
  14. }
  15. DWORD Result=0;
  16. if (dwPlatformId==VER_PLATFORM_WIN32_NT)
  17. Result=dwMajorVersion*0x100+dwMinorVersion;
  18. return Result;
  19. }
  20. // Replace it with documented Windows 11 check when available.
  21. #include <comdef.h>
  22. #include <Wbemidl.h>
  23. #pragma comment(lib, "wbemuuid.lib")
  24. static bool WMI_IsWindows10()
  25. {
  26. IWbemLocator *pLoc = NULL;
  27. HRESULT hres = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,
  28. IID_IWbemLocator,(LPVOID *)&pLoc);
  29. if (FAILED(hres))
  30. return false;
  31. IWbemServices *pSvc = NULL;
  32. hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,0,NULL,0,0,&pSvc);
  33. if (FAILED(hres))
  34. {
  35. pLoc->Release();
  36. return false;
  37. }
  38. hres = CoSetProxyBlanket(pSvc,RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,NULL,
  39. RPC_C_AUTHN_LEVEL_CALL,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE);
  40. if (FAILED(hres))
  41. {
  42. pSvc->Release();
  43. pLoc->Release();
  44. return false;
  45. }
  46. IEnumWbemClassObject *pEnumerator = NULL;
  47. hres = pSvc->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_OperatingSystem"),
  48. WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
  49. if (FAILED(hres))
  50. {
  51. pSvc->Release();
  52. pLoc->Release();
  53. return false;
  54. }
  55. IWbemClassObject *pclsObj = NULL;
  56. ULONG uReturn = 0;
  57. bool Win10=false;
  58. while (pEnumerator!=NULL)
  59. {
  60. HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
  61. if (uReturn==0)
  62. break;
  63. VARIANT vtProp;
  64. hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
  65. Win10|=wcsstr(vtProp.bstrVal,L"Windows 10")!=NULL;
  66. VariantClear(&vtProp);
  67. pclsObj->Release();
  68. }
  69. pSvc->Release();
  70. pLoc->Release();
  71. pEnumerator->Release();
  72. return Win10;
  73. }
  74. // Replace it with actual check when available.
  75. bool IsWindows11OrGreater()
  76. {
  77. static bool IsSet=false,IsWin11=false;
  78. if (!IsSet)
  79. {
  80. OSVERSIONINFO WinVer;
  81. WinVer.dwOSVersionInfoSize=sizeof(WinVer);
  82. GetVersionEx(&WinVer);
  83. IsWin11=WinVer.dwMajorVersion>10 ||
  84. WinVer.dwMajorVersion==10 && WinVer.dwBuildNumber >= 22000 && !WMI_IsWindows10();
  85. IsSet=true;
  86. }
  87. return IsWin11;
  88. }