Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Check If The .Net Framework Is Installed [C# / WPF]

Before starting my application (on Form Load) I want to check and ensure that the .NET framework (3.5 or higher) are installed on the machine - if not I want to prompt the user to download and install it (simple MessageBox with a INTERNET LINK to the Microsoft WebPage would be the best idea no?) So, this actually entails two questions...

a) How do I DETERMINE IF .NET FrameWork 3.5 or higher are installed? (I don't trust or want to just look for the C:\Program Files\Microsoft.NET folder, seems error-prone no?) Seeing as this is so very crucial there must be a nice way in C# to determine what version of .NET the user has running on his machine? I just have no clue how..

b) HOW do I paste an INTERNET LINK (hyperlink?) in a MessageBox? So that if the user does NOT have the .NET framework (1.1 or 2.0) installed I can have them simply click on the link to go download it?

Any help/hints would be greatly appreciated.

Thanks, Din

like image 712
dinbrca Avatar asked Feb 09 '11 12:02

dinbrca


People also ask

How do you check if .NET framework is installed?

The version of .NET Framework (4.5 and later) installed on a machine is listed in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. If the Full subkey is missing, then .NET Framework 4.5 or above isn't installed.

How do I know if .NET Framework is running?

Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to determine the version of . NET installed and press Enter: reg query "HKLM\SOFTWARE\Microsoft\Net Framework Setup\NDP" /s.


2 Answers

a) You would have to bootstrap the program with a non .NET language (C++, VB6, etc) instead of Form_Load (other posters are correct - if the framework isn't installed, the .NET program won't run). An example is here:

http://www.codeproject.com/KB/mcpp/DotNetTester.aspx

b) You can't put a hyperlink in a MessageBox, so you would have to create your own popup dialog (a form). EDIT: That form / dialog would have to be in the bootstrap program.

like image 175
RQDQ Avatar answered Oct 12 '22 00:10

RQDQ


You can not do this from your application. The application will fail to start.

One option you can do is make a ClickOnce installation that will verify that .NET is installed.

like image 39
Daniel A. White Avatar answered Oct 11 '22 23:10

Daniel A. White