讀取登錄檔獲取Windows系統XP/7/8/10型別
阿新 • • 發佈:2019-01-11
很多方案是採用GetVersion、GetVersionEx這兩個API來查詢作業系統的版本號來判斷當前的作業系統是Windows系列中的哪個,在Win10沒有出現前,這種方法是行的通的,但是Win10出現後此方法對於判斷Win10就不準了。
在此提供一個讀取登錄檔的方法,已經驗證過可行:
//檢視登錄檔獲知: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日 第一次更新