I posted some updated sample code last night that can be used to detect whether or not the various versions of the .NET Framework are installed on a system. To go along with this sample code, I wanted to also mention a consideration that developers should keep in mind when building an application that relies upon the .NET Framework.
It is common to see an application add code to their setup to check for the .NET Framework and install it as a prerequisite at setup time. It is less common (at least in my experience) for an application to perform a runtime check in your application startup code to validate that the necessary version of the .NET Framework is installed.
The .NET Framework can be independently uninstalled out from under your application if a user finds it and removes it in the Add/Remove Programs control panel. I strongly recommend adding logic like I demonstrated in my sample code to your application’s startup code paths. Doing so makes your application more bulletproof and allows you to display more user friendly error messages with exact steps that users can follow to resolve issues related to the .NET Framework.