Even though I vary rarely use Windows any more. I still get jobs from various people that request me to build a Windows program. One request that I got recently required the program to run differently depending on which version of Windows the program was installed on.
This left quite a few options opened.
Build the same program multiple times for different Windows versions (this would be an okay solution but then the user has to know which version of the program they need. Plus they may think one is better then the other. This could damage the marketing of the program.)
If you did decide to build multiple versions of the program you could place them into single installer, then have the installer ask the user which Windows version they are using. But still this isn't completely full proof.
Another option is to find files that specific to certain Windows OSes. This is the route I thought would have been best.
This particular program that was being made was for Windows XP, Windows Vista and Windows 7 systems. It dealt with certain directories in the systems.
Windows XP's users profile is the following directory. C:\Documents and Settings\User Name\
Windows Vista's and Windows 7's users profile is looks like the following. C:\Users\User Name
Now I could use Envirment Variables. But Windows XP use the My Documents directory, and Windows Vista and 7 use the Documents directory. And this was important. So envirnment variables was the only thing I needed to use.
I started out writing an If statement that looked like the following.
If %userprofile%\My Documents Exist Then
Run some commands.
Else If &userprofile%\Documents Exist Then
Run some other commands
The above sudo code would work for some cases. But not for this particular program. So I took the same idea and decided to make my program read registry values.
So I backed up the Windows Registry and then studied it. I found the registry Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
In here I found the Windows Version names and numbers. Since for each version number their can be several names I decided to use the numbers. So made my program detect the currentversion value.
If I wanted my program to be more specific such as make it work differently for Windows Vista Ultimate and Windows Vista Basic I would choose the product name value instead.
I hope this info comes in handy for fellow programmers.