读取注册表获取Windows系统XP/7/8/10类型(使用wcscmp比较wchar[]内容)

        很多方案是采用GetVersion、GetVersionEx这两个API来查询操作系统的版本号来判断当前的操作系统是Windows系列中的哪个,在Win10没有出现前,这种方法是行的通的,但是Win10出现后此方法对于判断Win10就不准了。

        在此提供一个读取注册表的方法,已经验证过可行:

[cpp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. //查看注册表获知:HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionCurrentVersion  
  2. //XP系统  5.1为XP,6.0为vista和2008, 6.1为win7, 6.2 Win8, 6.3 Win10  
  3. // 是否Win10系统  
  4. bool isSystemWin10()  
  5. {  
  6.     // GetVersion() 对于判断Win10系统不太合适  
  7.   
  8.     //打开注册表  
  9.     HKEY  hKey;  
  10.     LONG  nRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE,  
  11.                                 L"SOFTWARE\Microsoft\Windows NT\CurrentVersion",  
  12.                                 0,  
  13.                                 KEY_ALL_ACCESS,  
  14.                                 &hKey);  
  15.     if(nRet != ERROR_SUCCESS)  
  16.         return false;  
  17.   
  18.     //获取CurrentVersion  “6.3”  
  19.     WCHAR szCurrentVersion[100] = {0};  
  20.     DWORD dwSize = 100;  
  21.     DWORD type;  
  22.     nRet = RegQueryValueExW(hKey, L"CurrentVersion", NULL,&type, (BYTE *)szCurrentVersion, &dwSize);  
  23.     if(nRet != ERROR_SUCCESS)  
  24.         return false;  
  25.     if( wcscmp(szCurrentVersion,L"6.3")==0 )  
  26.         return true;  
  27.     else  
  28.         return false;  
  29. }  

2016年09月20日   第一次更新

http://blog.csdn.net/qq2399431200/article/details/52592941#comments

原文地址:https://www.cnblogs.com/findumars/p/6568968.html