Get Windows Version

How to get the Windows Version from the System Registry

The Windows version is stored in the registry key: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion

 

The value CurrentVersion contains the version number as string(!):

Version Number: Operating System:
5.0 Windows 2000
5.1 Windows XP
5.2 Windows XP 64bit
5.2 Windows Server 2003 / R2
6.0 Windows Vista / Windows Server 2008
6.1 Windows 7 / Windows Server 2008 R2
6.2 Windows 8 / Windows Server 2012
6.3 Windows 8.1 / Windows Server 2012 R2
10.0 Windows 10 (Preview)

 

The value ProductName contains the system name, e.g. "Windows 8.1"

 

 

Helper function to read a string value from the registry:

CString GetStringFromReg(HKEY keyParent, CString keyName, CString keyValName)
{
    CRegKey key;
    CString out;
    if (key.Open(keyParent, keyName, KEY_READ) == ERROR_SUCCESS)
    {
        ULONG len=256;
        key.QueryStringValue(keyValName, out.GetBuffer(256), &len);
        out.ReleaseBuffer();
        key.Close();
    }
    return out;
}

 

Get the OS version (e.g. "6.3")

CString osversion = GetStringFromReg(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CurrentVersion");

 

Get the OS name (e.g. "Windows 8.1")

CString osname = GetStringFromReg(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductName");

Disclaimer: The information on this page is provided "as is" without warranty of any kind. Further, Arclab Software does not warrant, guarantee, or make any representations regarding the use, or the results of use, in terms of correctness, accuracy, reliability, currentness, or otherwise. See: License Agreement