Working on a project and need to be able to determine whether the O/S is Windows 7, Vista or default to XP. I understand I could run into Win2K and earlier versions but let's just say that's not a concern as other code will catch that before it gets to this point. My application will be in C++ for the time being using VS2005. I've found articles and sample code alike but they seem way bloated for my uses. Just looking for a quick and dirty return.
http://msdn.microsoft.com/en-us/library/ms724358%28VS.85%29.aspx
Generally, you can use
GetVersionEx
to find the Windows version. A safer way would perhaps be to useVerifyVersionInfo
. There are C examples for bothGetVersionEx
andVerifyVersionInfo
.However, as repeatedly stated on MSDN checking for the operating system version is usually not the best way of determining whether a particular feature is present.
List of Windows Version, using
GetVersionEx
:In general, you don't want to be testing against a specific version number, but rather checking for a particular feature. If you really want to detect "Windows 7 or later," however...
For 2000, compare major and minor against 5 and 0, respectively. For XP, compare against 5 and 1. For Vista, 6 and 0.
The Windows 8.1 SDK1) introduced a number of Version Helper functions, that help determine the version of the OS an application is running on:
If you need to distinguish between client and server editions of Windows, you can call IsWindowsServer.
1) The Windows 8.1 SDK can be used to build applications for all supported versions of Windows.