1

How can I check .Net Framework 4.8 installed on machine using C# WinForms application.

Now our application running on .net Framework 4.0 but we required to upgrade its to .Net Framework 4.8. So before upgrading .net framework we required to check .net framework 4.8 installed on user machine on not.

Thanks All.

A. S. Mahadik
  • 585
  • 1
  • 5
  • 17
  • 1
    [Configure what .NET version should be installed by windows installer](https://stackoverflow.com/a/48850864/3110834) – Reza Aghaei Feb 21 '22 at 10:55
  • 1
    All installers have a *prerequisite* section that can be configured to check specific .Net versions (plural) and install from a local repository, or download from the Web if that's what has been specified. – Jimi Feb 21 '22 at 10:58
  • 1
    If you aren't intending to support Windows 7 or older, or any unsupported old versions of Windows 10, then .net 4.8 will always be installed. – Matthew Watson Feb 21 '22 at 10:58
  • 2
    [How to: Determine which .NET Framework versions are installed](https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed?WT.mc_id=DT-MVP-5003235) – Reza Aghaei Feb 21 '22 at 10:59
  • 1
    @Matthew Watson .Net Framework 4.8 is supported in Windows 7. – Jimi Feb 21 '22 at 10:59
  • 1
    @Jimi But it may be absent. – GSerg Feb 21 '22 at 11:00
  • 1
    @GSerg That's what the prerequisites are for and what the installer can be instructed to do in case it's missing. – Jimi Feb 21 '22 at 11:02
  • 1
    @Jimi Prerequisites have nothing to do with [your objection](https://stackoverflow.com/questions/71205052/how-can-i-check-net-framework-4-8-installed-on-machine?noredirect=1#comment125864005_71205052) to [Matthew Watson's comment](https://stackoverflow.com/questions/71205052/how-can-i-check-net-framework-4-8-installed-on-machine?noredirect=1#comment125863972_71205052). – GSerg Feb 21 '22 at 11:03
  • 1
    @GSerg The way the phrase is constructed (and in relation to what the OP is asking), it may *sound like* that .Net FW 4.8 is not supported in Windows 7. I'm saying this because I've seen a number of people, recently, stating that Windows 7 doesn't support it, so better write it down. I don't Matthew Watson is *offended* by this. – Jimi Feb 21 '22 at 11:06
  • 3
    @Jimi It's supported but NOT guaranteed to be installed. On current versions of Windows 10 and Windows 11 it IS guaranteed to be installed. All I'm saying is that if you're only targeting SUPPORTED versions of Windows, then .net 4.8 is guaranteed to be installed. – Matthew Watson Feb 21 '22 at 11:10
  • 1
    @MatthewWatson: As far as I know, on Windows Server (which is a supported version of Windows), .net Framework is still an optional component. – Heinzi Feb 21 '22 at 11:14
  • 1
    @Heinzi True, but that's a server - I was talking about Windows 10 and Windows 11 specifically. – Matthew Watson Feb 21 '22 at 11:18
  • 2
    @MatthewWatson Windows 10 1809 Enterprise if Windows Update cannot / is not run. -- Anyway, you not always have the luxury to support just what Microsoft still supports. – Jimi Feb 21 '22 at 11:19
  • 2
    @Jimi Tell me about it - we still have to support Windows 7 for some hospitals... But for most of our stuff, we have a check that it's being installed on a supported Windows 10 or 11 client. Otherwise we'd have to do all our testing on all the old versions that we allow the application to be installed on, which would be an insane overhead. – Matthew Watson Feb 21 '22 at 11:25
  • Thanks All But I required to check .Net FW 4.8 installed on windows machine using Windows application. Prerequisites are good suggestion but there is policy we are not able to download. So first we required to analyze which .Net FW installed in machine using our current application. So we can collect this data and ask user to update .Net framework if .net FW 4.8 is not available on any user machine then we ask user to update before application FW upgrade. – A. S. Mahadik Feb 21 '22 at 13:15
  • You don't need to download the package, you can add it to the package the installer prepares for your application's deployment. So it's already part of the installation package. It will be installed if necessary. – Jimi Feb 21 '22 at 15:47

1 Answers1

3

Since you mentioned in your question that you need this for a WinForms application, the recommended way is to configure the supportedRuntime element in your application's config file with the appropriate SKU, e.g.

<configuration>
   <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
   </startup>
</configuration>

Alternatively, if, for whatever reason, you need to check for the presence of .NET Framework 4.8 after starting your application, you can look at the Release value of the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full

A value of 528040 or higher indicates that .NET Framework 4.8 (or higher) is installed.

Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • 2
    Note: I am aware that MS said that there'll be no higher .NET Framework (4) version than 4.8, but, well, they also said that there'd be no new Windows release after Windows 10 either and now we have Windows 11, so... – Heinzi Feb 21 '22 at 11:11
  • 1
    Thanks But I required to check .Net FW 4.8 installed on windows machine using Windows application. Prerequisites are good suggestion but there is policy we are not able to download. So first we required to analyze which .Net FW installed in machine using our current application. So we can collect this data and ask user to update .Net framework if .net FW 4.8 is not available on any user machine then we ask user to update before application FW upgrade – A. S. Mahadik Feb 21 '22 at 13:16