0

I can use the GetVersionEx() function to get the Windows version, but this function will return a number and not a string. But there is no problem as I can convert the number to a string, for example:

if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1)
{
    printf("%s\n", "Windows 7");
}

But what if a new Windows version came out after releasing my program. I have to recompile my program to add the new Windows version!

2 Answers2

3

You should query Caption of Win32_OperatingSystem.

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
0

You could query the system registry and get the data from the following location. To see the registry functions visit the MSDN page of Registry Functions.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

Information Provided

  • ProductName: The Operation System Name ex "Windows 8.1"
  • SoftwareType: The type of the software ex "System" or "Server"
  • CurrentVersion: It contains the version such as 6.3
David
  • 4,313
  • 1
  • 21
  • 29
  • Who says that key will still be used in a future release. Is it documented now? – David Heffernan Mar 28 '15 at 21:45
  • @DavidHeffernan you are completely correct. I couldn't find any reference that this key will exist in the future. The best solution is to use [WMI](https://msdn.microsoft.com/en-us/library/aa394582%28v=vs.85%29.aspx) and com calls from C. I just wanted to provide another option. – David Mar 28 '15 at 21:53