How to check the .net framework version on start of WinForms application that wrote on .NET 3.5? If .net 3.5 is not installed, the application should show the message about it (may be with link on .net installer or some else). Now it show some error that is not clear for user.
You have to create a starter app written either in .Net 2.0 or as an unmanaged app (to cover if there's no version of .Net installed at all) and start that first and then if .Net 3.5 is installed it'll start the real app, otherwise it'll show a nice error message.
However, the even better solution would be to have your installer install .Net 3.5, that way you won't have to worry about it (but this obviously won't work for XCopy deployment etc).
Doing that in a .NET 3.5 application is going to be kinda hard, since you never get to the point where your application is started.
Generally this is done in the installer for the application, by adding a launch condition. See http://support.microsoft.com/kb/315291
EDIT: I found an article that explains how to write an unmanaged application to run before your .NET application starts (as suggested in ho1's answer) http://blogs.msdn.com/b/astebner/archive/2009/01/31/9387659.aspx
I re-read your question - you cannot run .NET x ver app when .NET x is not installed! The end.
If you have it installed, then for other purpose-
Use System.Environment.Version
to find which version you are using currently.
To know about all the versions installed, check this.
Enumerate the subkeys of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP. Each subkey is a .Net version. It should have Install=1 value if it's present on the machine, an SP value that shows the service pack and an MSI=1 value if it was installed using an MSI. (.Net 2.0 on Vista doesn't have the last one for example, as it is part of the OS)
You can access this registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP" and iterate over the values.
Check out this C++ project that should do what you're asking for.
http://www.codeproject.com/KB/mcpp/DotNetTester.aspx
You'd just set up your shortcuts to launch that app, which would in turn launch your .net app.
From the project description:
For example (test for a minimum of FW 1.1 and launch an application):
dotNetTester.exe 1.1 C:\Temp\Myapp.exeC:\Temp\Myapp.exe