How to get the OS version in Win8.1 as GetVersion/GetVersionEx are deprecated?

16.4k views Asked by At

I have scenarios where i want to specifically know the OS major/minor version and build number etc.

From windows 8.1 onwards GetVersion and GetVersionEx have been deprecated, stating:

[GetVersion/GetVersionEx may be altered or unavailable for releases after Windows 8.1. Instead, use the Version Helper functions]

None of the version helper APIs help me get the OS version number rather help me verify or get to know if my version is same or above some mentioned version. What can be done?

3

There are 3 answers

3
xMRi On

There is a new function named GetProductInfo that returns version infos.

If you want to test for a specific version you should use even VerifyVersionInfo

It is easy to create a structure to check whether a specific OS version is running. VerifyVersionInfo takes to version structures and you can easily check for VER_GREATER_EQUAL and VER_LESS_EQUAL

Also note that GetVersionEx doesn't lie on a Windows 8.1 system if you define the correct supported OS entry in the compatibility section for your manifest. But it may lie in a future OS version!

See Targeting your application For Windows 8.1 for a list of GUIDs. Also covered here.

GUID list for the application manifest

  • Vista: {e2011457-1546-43c5-a5fe-008deee3d3f0}
  • Windows 7: {35138b9a-5d96-4fbd-8e2d-a2440225f93a}
  • Windows 8: {4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}
  • Windows 8.1: {1f676c76-80e1-4239-95bb-83d0f6d0da78}
  • Windows 10: {8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}
5
NuSkooler On

The API GetVersionEx() continues to work in Windows 8.1+, but Microsoft has altered its functionality. From MSDN (emphasis mine):

With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested.

Applications not manifested for Windows 8.1 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases. To manifest your applications for Windows 8.1 please refer to Targeting your application for Windows 8.1.

What you need to do is add the proper GUID(s) to your application (.exe/.dll) binaries (via manifest XML information). In other words, if you specifically state your application supports 8.1, GetVersionEx() will return proper information when running on Windows 8.1. If you do not, GetVersionEx() will lie to you.

See Targeting your application For Windows 8.1 for a list of GUIDs. Also covered here and here.

GUID List for the Lazy

  • Vista / Server 2008: {e2011457-1546-43c5-a5fe-008deee3d3f0}
  • Windows 7 / Server 2008 R2: {35138b9a-5d96-4fbd-8e2d-a2440225f93a}
  • Windows 8 / Server 2012: {4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}
  • Windows 8.1 / Server 2012 R2 : {1f676c76-80e1-4239-95bb-83d0f6d0da78}
  • Windows 10 / Server 2016: {8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}

As for Windows Server 2019, I'm not sure that a new GUID has been released. Please comment if you know more!

0
Abdallah Shakhatreh On

Check this article on codeproject.com, It's working perfectly for Windows 8 :

1) Download .DLL and add it to your project .

2) Use this code to get Operation System Information :

StringBuilder sb = new StringBuilder(String.Empty);
sb.AppendLine("Operation System Information");
sb.AppendLine("----------------------------");
sb.AppendLine(String.Format("Name = {0}", OSVersionInfo.Name));
sb.AppendLine(String.Format("Edition = {0}", OSVersionInfo.Edition));
if (OSVersionInfo.ServicePack!=string.Empty)
sb.AppendLine(String.Format("Service Pack = {0}", OSVersionInfo.ServicePack));
else
sb.AppendLine("Service Pack = None");
sb.AppendLine(String.Format("Version = {0}", OSVersionInfo.VersionString));
sb.AppendLine(String.Format("ProcessorBits = {0}", OSVersionInfo.ProcessorBits));
sb.AppendLine(String.Format("OSBits = {0}", OSVersionInfo.OSBits));
sb.AppendLine(String.Format("ProgramBits = {0}", OSVersionInfo.ProgramBits));

textBox1.Text = sb.ToString();