Does anyone know how to check for Version 2 of the .NET Framework during Runtime? VB.NET

Posted on 2006-03-29
Medium Priority
Last Modified: 2010-04-23
Does anyone know how to check for Version 2 of the .NET Framework during Runtime? VB.NET
Question by:pgilfeather
  • 2
LVL 52

Expert Comment

by:Carl Tawn
ID: 16323980
If your app is compiled against .Net 2.0 and you try to run it on a machine without .Net 2.0 then it will fail. You wouldn't be able to check for it because your app won't run. Bit of a "Catch 22" situation.
LVL 13

Accepted Solution

Corey Scheich earned 2000 total points
ID: 16323981
 I have used this to figure out what the current version is I couldn't find a regKey so I used the install folders to figure it out.

Public Function GetCurrentFrameworkVersionString () as string    

        Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
        Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
        Dim Key As Microsoft.Win32.RegistryKey = hklm.OpenSubKey("SOFTWARE\Microsoft\.NETFramework\")
        Dim FrameWork As System.IO.DirectoryInfo
        Dim CurrentFrameWork() As System.IO.DirectoryInfo

        If Not Key Is Nothing Then
            Dim count As Long = 0
            Dim RegAsmPath As String = ""
            Dim Version As String = ""

            FrameWork = New System.IO.DirectoryInfo(Key.GetValue("InstallRoot", "C:\WINDOWS\Microsoft.NET\Framework\"))
            CurrentFrameWork = FrameWork.GetDirectories("v*.*")
            For count = 0 To CurrentFrameWork.GetUpperBound(0)
                If CurrentFrameWork(count).Name > Version Then
                    Version = CurrentFrameWork(count).Name
                    RegAsmPath = CurrentFrameWork(count).FullName & "\Regasm.exe"
                End If
            Return Version
End Function

Author Comment

ID: 16324140
Is there any situation that this might not work?

Could the framework have been installed in a slightly different directory depending on the operating system?
LVL 13

Expert Comment

by:Corey Scheich
ID: 16325419
I think it should work on any Windows Machine I don't know about Mac Linux and such.
if the registry key for the InstallRoot (which should contain the .Net installation location) isn't found then it defaults to "C:\WINDOWS\Microsoft.NET\Framework\" which is the installation location for a single boot machine that has windows XP installed.

Alternatively you could do this.

       Dim Key As Microsoft.Win32.RegistryKey = hklm.OpenSubKey("SOFTWARE\Microsoft\.NETFramework\policy\v2.0")

       if Key.GetValue("50727", "") <> "50727-50727" then
             msgbox "The v2.0 of the .NET Framework was not found on this system"
             msgbox "The v2.0 of the .NET Framework was found on this system"
      end if

this is the key that is checked in an install program as described in this article.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question