Link to home
Start Free TrialLog in
Avatar of William White
William WhiteFlag for United States of America

asked on

How to check is VB.net 3.0 is installed using a vb.net 2.0 application

All,
What code would i need to check to see if VB.net 3.0 is installed using a vb.net 2.0 application
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

I had to find that 2 weeks ago!
    Private Enum enuFrameworkVersion
        Unknown
        'Fx10
        Fx11
        Fx20
        Fx30
        Fx35
    End Enum
 
    Private Function GetFrameworkVersion() As String
        Dim intFXVerion As enuFrameworkVersion = enuFrameworkVersion.Unknown
 
        Dim strPath As String = "Software\Microsoft\NET Framework Setup\NDP\"
 
        If cRegistry.ReadSetting(Registry.LocalMachine, strPath + "v3.5", "Install", String.Empty) = "1" Then
            intFXVerion = enuFrameworkVersion.Fx35
        ElseIf cRegistry.ReadSetting(Registry.LocalMachine, strPath + "v3.0", "Install", String.Empty) = "1" Then
            intFXVerion = enuFrameworkVersion.Fx30
        ElseIf cRegistry.ReadSetting(Registry.LocalMachine, strPath + "v2.0.50727", "Install", String.Empty) = "1" Then
            intFXVerion = enuFrameworkVersion.Fx20
        ElseIf cRegistry.ReadSetting(Registry.LocalMachine, strPath + "v1.1.4322", "Install", String.Empty) = "1" Then
            intFXVerion = enuFrameworkVersion.Fx11
        End If
 
        Return intFXVerion.ToString
    End Function

Open in new window

Avatar of William White

ASKER

i can see to use cregistry, i get cregistry is not declared what can i do to use that?
cRegistry is a wrapper class to access the registry. Here is what you need:

	Public Shared Function ReadSetting(ByVal RK As RegistryKey, _
			   ByVal pstrSubKey As String, _
			   ByVal pstrName As String, _
			   ByVal pstrDefault As String _
			  ) As String
		Dim objKey As RegistryKey
 
		Try
			objKey = RK.OpenSubKey(pstrSubKey, False)
			If objKey Is Nothing Then
				objKey = RK.CreateSubKey(pstrSubKey)
			End If
			Return objKey.GetValue(pstrName, pstrDefault).ToString
			objKey.Close()
		Catch ex As Exception
			Throw ex
		Finally
			objKey = Nothing
		End Try
	End Function

Open in new window

so with this new code how do i apply it to find out if dot.net 3.0 is installed? i like the cregistry however i don't know how to use it. I am using VS2008
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for all the help