Many scenarios are using GetVersion, GetVersionEx these two APIs to query the operating system version number to determine the current operating system is the Windows family which, before the Win10, this method is the line of the pass, But after the appearance of Win10, this method is not allowed to judge Win10.
Here is a way to read the registry, which has been verified to be feasible:
[CPP]View PlainCopy
- Viewing the registry learn: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Nt\currentversion\currentversion
- XP System 5.1 is xp,6.0 for Vista and 2008, 6.1 for Win7, 6.2 Win8, 6.3 Win10
- Whether the WIN10 system
- BOOL IsSystemWin10 ()
- {
- //GetVersion () is not suitable for judging the WIN10 system
- //Open the registration form
- 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;
- //Get 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;
- }
September 20, 2016 first update
Http://blog.csdn.net/qq2399431200/article/details/52592941#comments
Read the registry to get the Windows system XP/7/8/10 type (using wcscmp compare wchar[] content)