Austin
Austin

Reputation: 4929

How to accurately get Windows OS version with C++?

Every link I look at always mentions GetVersionEx, but that doesn't seem very helpful.

My method looks like this,

static int windowsVersion() {
       OSVERSIONINFO osvi;

   ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
   GetVersionEx(&osvi);
   return osvi.dwMajorVersion;
}

Which I am running Windows 8 and instead it returns 6.

If I'm trying to accurately get their version of Windows, that isn't very helpful.

Note: I've also checked all the other variables. the dwMinorVersion returns a 4, build number returns something like 8400.

Upvotes: 1

Views: 3689

Answers (3)

qehgt
qehgt

Reputation: 2990

Manual: For Windows 8, dwMajorVersion is 6 and dwMinorVersion is 2

Upvotes: 5

Jesse Good
Jesse Good

Reputation: 52365

A 6 for dwMajorVersion can mean anything from Windows Vista and up. That's how Microsoft versioning works. 2 for dwMinorVersion should be either Windows 8 or Windows Server 2012. If wProductType == VER_NT_WORKSTATION, you got Windows 8. All of this is explained on MSDN.

Upvotes: 3

Mark Hall
Mark Hall

Reputation: 54562

You need to use both the Major and Minor Version Numbers.

Windows Vista 6.0.6000
Windows 7 6.1.7600
Windows 8 64 bit version on my PC returns 6.2.9200

Upvotes: 3

Related Questions