讀取註冊表擷取Windows系統XP/7/8/10類型(使用wcscmp比較wchar[]內容)

來源:互聯網
上載者:User

標籤:註冊表   _for   win10   知識   value   操作   detail   track   vista   

        很多方案是採用GetVersion、GetVersionEx這兩個API來查詢作業系統的版本號碼來判斷當前的作業系統是Windows系列中的哪個,在Win10沒有出現前,這種方法是行的通的,但是Win10出現後此方法對於判斷Win10就不準了。

        在此提供一個讀取註冊表的方法,已經驗證過可行:

 

[cpp] view plain copy  
  1. //查看註冊表獲知:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion  
  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

讀取註冊表擷取Windows系統XP/7/8/10類型(使用wcscmp比較wchar[]內容)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.