標籤:註冊表 _for win10 知識 value 操作 detail track vista
很多方案是採用GetVersion、GetVersionEx這兩個API來查詢作業系統的版本號碼來判斷當前的作業系統是Windows系列中的哪個,在Win10沒有出現前,這種方法是行的通的,但是Win10出現後此方法對於判斷Win10就不準了。
在此提供一個讀取註冊表的方法,已經驗證過可行:
[cpp] view plain copy
- //查看註冊表獲知:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion
- //XP系統 5.1為XP,6.0為vista和2008, 6.1為win7, 6.2 Win8, 6.3 Win10
- // 是否Win10系統
- bool isSystemWin10()
- {
- // GetVersion() 對於判斷Win10系統不太合適
-
- //開啟註冊表
- HKEY hKey;
- LONG nRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
- L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
- 0,
- KEY_ALL_ACCESS,
- &hKey);
- if(nRet != ERROR_SUCCESS)
- return false;
-
- //擷取CurrentVersion “6.3”
- WCHAR szCurrentVersion[100] = {0};
- DWORD dwSize = 100;
- DWORD type;
- nRet = RegQueryValueExW(hKey, L"CurrentVersion", NULL,&type, (BYTE *)szCurrentVersion, &dwSize);
- if(nRet != ERROR_SUCCESS)
- return false;
- if( wcscmp(szCurrentVersion,L"6.3")==0 )
- return true;
- else
- return false;
- }
2016年09月20日 第一次更新
http://blog.csdn.net/qq2399431200/article/details/52592941#comments
讀取註冊表擷取Windows系統XP/7/8/10類型(使用wcscmp比較wchar[]內容)