If you're trying to do this from managed code, take a look at this article, which wraps all of the logic needed to determine if a specific Framework version is installed.
Otherwise, take a look at Aaron's blog post here, which gives a C/C++ method for doing the same thing.