views:

94

answers:

4

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?

+3  A: 

Have a look at this: http://msdn.microsoft.com/en-us/library/ms724429%28VS.85%29.aspx

Nick Bedford
Was hoping for a built-in function, but I guess this is the best there is. :( Thanks.
Colen
Win32 isn't the funnest API to use :-P
Nick Bedford
A: 

and also have a look at this: http://www.codeproject.com/KB/macros/winver%5Fmacros.aspx

didito
A: 

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%5Fof%5FMicrosoft%5FWindows#Windows%5FNT

// (bad) example to check if we're running Windows XP
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
{
    // Windows XP
}
Josh
A: 

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?

Thomas Bratt