How do I get a description of the current OS version in windows?

I need to get a simple description of the OS, such as "Windows XP (SP2)" or "Windows 2000 Professional" to include in some debugging code. Ideally, I'd like to simply retrieve it by calling a "GetOSDisplayName" function.

Is there such a function available for C++ win32 programming?

13.10.2009 22:34:01
5 ОТВЕТОВ
РЕШЕНИЕ
4
13.10.2009 22:37:15
Was hoping for a built-in function, but I guess this is the best there is. :( Thanks.
Colen 14.10.2009 02:26:04
Win32 isn't the funnest API to use :-P
Nick Bedford 14.10.2009 02:42:33
1
13.10.2009 23:36:58

And here's an example from something I came across recently:

OSVERSIONINFO osvi;

ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

GetVersionEx(&osvi);
// use osvi.dwMajorVersion and osvi.dwMinorVersion

You'll need to run some tests to check which versions of windows the numbers correspond to. this might help: http://en.wikipedia.org/wiki/History_of_Microsoft_Windows#Windows_NT

// (bad) example to check if we're running Windows XP
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
{
    // Windows XP
}
0
14.10.2009 00:19:44

Please find below a link to a related .NET question and set of answers. The C++/Win32 answer is essentially the same after some trivial mapping between .NET and C++/Win32.

How to translate MS Windows OS version numbers into product names in .NET?

0
23.05.2017 12:26:46

If you are looking for the productName+version that marketing uses, it's in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Product Name

Looking at my computer, it says "Windows 8.1 Pro".

2
8.05.2014 05:19:23