I am intending to write code to determine if the OS is Windows XP, so I can set the LOCALAPPDATA environment variable to work-around a whole load of code which uses ExpandEnvironmentVariables() heavily.
To make it even more fun, some code is written in VB6, and some code is written in C# 4.0 . Looking at the documentation for GetVersionEx(), there are strong suggestions that this API call will be deprecated from Windows 8.1 onwards. But no problem, there is a different set of API calls (VerifyVersionInfo / VerSetConditionMask) I can use. With VB6, there is no choice - I have to use the API call.
However, with my C# code, there appears to be no obvious equivalent. There is Environment.OSVersion, but this seems to be a hacked together set of data from disparate sources, and there isn't anything with the subtlety of the VerifyVersionInfo() API.
Is there a wrapper for this API call. If not, should I bother implementating it myself?
[Added] Or otherwise, maybe someone might have some internal information about how the Environment.OSVersion is implemented?
It's perfectly fine to use GetVersionEx. It won't be removed from Windows for a very long time, if ever. Microsoft has a long track record of maintaining compatibility with old programs. For example, you can still call the Win16 APIs that were deprecated 20 years ago.
First of all it is important to understand what Deprecated
means. It means that the function either is critically broken (such as some early threading), or that it's been superseded (replaced) with new functionality. In this case it is the latter.
From the documentation on GetVersionEx function there is a link suggesting to use Version Helper APIs instead.
One part of this page is specifically important:
Note These APIs are defined by versionhelper.h, which is included in the Windows 8.1 Preview software development kit (SDK). This file can be used with other Microsoft Visual Studio releases to implement the same functionality for Windows versions prior to Windows 8.1 Preview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With