When a new OS is released, a high percentage of applications don’t install or don’t run because they check for a specific OS version. The application or installer checks for a specific version number and exits if it isn’t what is expected. I’ve heard claims of up to 50% of incompatibility issues are due to a simple version checks. So many applications check version that this influences how Microsoft increments version number.
It’s true. If you look at the version number of Windows 7, it’s version 6.1.
Microsoft Windows [Version 6.1.7600]
This was done for application compatibility. Most of the time, developers only check the major version. So, if Microsoft knows that application compatibility is very good between releases, only the minor version number is incremented. This trick was also done from Windows 2000 (5.0) to Windows XP (5.1).
Let’s say you only want your application to install on XP. Your installer checks the OS version and exits if it’s not equal to 5.1. There’s a compatibility feature that has been in Windows since Windows 2000 called “shims”. Shims “trick” API calls by acting like a legacy OS. The “version lie” shim returns whatever OS version you want. Therefore, the installer can be tricked and the application can be installed regardless of the version check. The “version lie” shim can be implemented several different ways -- by the user via the Compatibility tab in properties, the built-in “shim database”, by enterprise administrators via the ACT Toolkit, and by the Program Compatibility Assistant.
The best option for checking version is to not do it. Sometimes you may feel that you need to check version (especially if your boss tells you). Checking version and blocking the installation or exiting won’t stop the user if they are determined. In fact, if you just exit, the user has no idea what has gone wrong.
The following table outlines why you may be version checking and suggestions to avoid problems:
hMod = LoadLibrary(L"Apphelp.dll");
if (hMod) return hMod;
hMod = LoadLibrary(L"sdbapiu.dll");
hMod = LoadLibrary(L"sdbapi.dll");
if (hMod) return hMod;
One of the unusual side affects of version checking deals with upgrade scenarios. Here’s where version checking can get you into trouble.
If you decide to check version. Make sure you think through changes in major and minor version numbers. If you check for Windows 7, check for Windows 7 and greater so you don’t break when then next OS is released.
Here’s some sample code that checks for OS versions:
if (dwMajorVersion >= 6 && dwMinorVersion >= 0) printf("MajorVersion>=6 && MinorVersion>=0. I'm Vista or greater\n"); else if (dwMajorVersion==5 && dwMinorVersion>=1) printf("MajorVersion==5 && MinorVersion>=1. I'm XP\n"); else if (dwMajorVersion==5 && dwMinorVersion==0) printf("MajorVersion==5 && MinorVersion==0. I'm Win 2000\n"); else printf("MajorVersion<5. I'm older than Win 2000\n");