6

I got at task to extend en existing WinForm application to make a check weather or not the required .NET Framework (fx. 3.5) is installed.

Well the issues is that - if there is no .NET Framework installed, the winform program is not able to run at all... I assume.

I could (maybe) do like suggested here: (and make a c++ program that should start first, make the check and then launch the application) Check on .Net framework version from WinForms app But I would rather not go into c++.

Another way seems to be this solution: Why isn't an exception thrown when the right .NET framework version is not present? ... where you configure your application in app.config. But I doubt that will work if there i no .NET framework installed.

<startup>
    <supportedRuntime version="v3.5" />
</startup>

So my question is what is Best Practice in this area? Should I make the check one way or the other, or should I just make it a pre-requisite, that fx. .NET Framework version 3.5 is demanded?

10
  • 1
    Normally you would have an installer which checks the .NET framework version and installs it if it's not yet installed. For just a EXE I have no clue. Commented Apr 24, 2014 at 12:34
  • 1
    What does checking for the .NET framework actually gain you? What are you trying to ultimately do? Commented Apr 24, 2014 at 12:35
  • 4
    Windows comes with some version of .NET pre-installed since Windows XP (I think) and it's not easy to uninstall it. Just to let you know. Commented Apr 24, 2014 at 12:37
  • 1
    I think the comments are right on: If you want the lowest-common denominator, target .NET 2.0 and assume no customers are using Windows 2000 or earlier. Otherwise, build an installation package with something like NSIS and install the correct .NET runtime as needed, ideally shipping with the relevant redistributable package. Commented Apr 24, 2014 at 12:45
  • @justin Skiles: The purpose of the program is to be an installer for "a suite" of programs/settings he can choose. It is not made as an installation package, but is a Win-form that guides the user (usually IT-person) through several selections. (at the moment I cannot give more details, as I am only one month in the job). So this check for .NET Framework is more a convenience for the person who installs the program - and to fast give feedback that something is missing. Commented Apr 24, 2014 at 13:25

6 Answers 6

3

If the required framework is not installed, your application won't run, so checking if the framework is installed from within your app is checking something you already know to be true.

If you want to check that the framework is installed, you really need to do this from within a a bootstrapper exe either written in a .NET version you know will exist (like .NET 2 as it gets installed on the machine with the OS) or some other language like C++.

You can check in the registry (HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP) to see what frameworks are installed. This can easily be done in C# or any other language.

C# code something like this:

var baseKeyName = @"SOFTWARE\Microsoft\NET Framework Setup\NDP";
var installedFrameworkVersions = Registry.LocalMachine.OpenSubKey(baseKeyName);

var versionNames = installedFrameworkVersions.GetSubKeyNames();
Sign up to request clarification or add additional context in comments.

Comments

0

If you are deploying often for limited set of users, you should check out ClickOnce (http://msdn.microsoft.com/en-us/library/t71a733d(v=vs.80).ASPX)

It is a bit like Windows Installer, but simplified a lot. From the user perspective application will look like desktop icon. When you click on the icon, it will automatically check all the requirements and install the latest version of your software if it has been updated. This way you can ensure that users always has the required framework installed, as well users always will use the latest version.

3 Comments

Worth mentioning that this will require an Internet connection available for the users.
@Avi Turner: You don't neccesary need an Internet connection, a connection to local network would be sufficient if the application is served from local network.
@AviTurner Your comment is inaccurate. ClickOnce offers various means of distribution (even via optical media).
0

To Check .net frame work version follow http://support.microsoft.com/kb/318785

Comments

0

I got at task to extend en existing WinForm application to make a check weather or not the required .NET Framework (fx. 3.5) is installed

This doesn't makes sense, because it will not run if required component is missing.

As already mentioned, typically installer is responsible for the job to check for components, interrupt installation, download and install them.

But in any case, nothing prevents you to make bootstrapper, which will be able run in majority of times (aka required less/none components) and which will run your .net application. It can be organized in multiple ways: exe + exe (often renamed), exe + dll, exe + embedded resource (extract and run), etc...

If you think to use MS Visual C++ to make bootstrapper, then here is a bad new for you: it required component to be installed (yes, that's stupid, but it needs Microsoft Visual C++ 200x redistributable). So it would be again a job for installer, or you will have to learn how to write C/C++ pure WinAPI software, which is a pain, but doable.

To example, this is a check for .Net Framework 4.0

// check if net framework 4.0 or higher is installed
HKEY hkey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Net Framework Setup\\NDP\\v4", 0, KEY_READ, &hkey) != ERROR_SUCCESS)
    ; // some error
RegCloseKey(hkey);

Doesn't looks complicated? Then go ahead!

Comments

0

You are right about the program not running if the required .NET version is not installed. You could use a bootstrapper, as others have said. You could simply let the application fail at runtime with the default message box that appears whining about the missing dependency.

Another valid approach would be hosting the CLR yourself. Here:

It's mostly like a bootstrapper too, but instead of launching the second (.NET-dependent) application it just loads it into the same process (if available).

Comments

0

You could create a batch (.bat) file to verify the existence of the .NET Framework folders:

IF EXIST C:\WINDOWS\Microsoft.NET\Framework[framework version here] (goto launchprogram) else goto errormessage

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.