check .net framework is installed

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
is it possible to use vb.net so see if the .net framework is installed? if not, then how would i do it in vb6?
 
Joined
Jan 3, 2005
Messages
10
Location
KY, USA
Programming Experience
1-3
So you can have your setup see if framework is on a machine? and if not can be load on? Just like VS.Net?

David J Harmon
 

TLWallace

Member
Joined
Dec 30, 2004
Messages
8
Programming Experience
5-10
Don't know if this will help but here's a method to check which Framework version is installed.

Option Explicit On

Option Strict On

Imports
System

Imports Microsoft.Win32

Imports Microsoft.VisualBasic


Module Module1
Private Declare Auto Function GetSystemMetrics Lib "user32" (ByVal value As Integer) As Integer

Private Const SM_TABLETPC As Integer = 86

Private Const SM_MEDIACENTER As Integer = 87

' Constants that represent registry key names and value names to use for detection

Private Const NET_FX_10_REG_KEY_NAME As String = "Software\Microsoft\.NETFramework\Policy\v1.0"

Private Const NET_FX_10_REG_KEY_VALUE As String = "3705"

Private Const NET_FX_10_SPx_MSI_REG_KEY_NAME As String = _

"Software\Microsoft\Active Setup\Installed Components\{78705f0d-e8db-4b2d-8193-982bdda15ecd}"

Private Const NET_FX_10_SPx_OCM_REG_KEY_NAME As String = _

"Software\Microsoft\Active Setup\Installed Components\{FDC11A6F-17D1-48f9-9EA3-9051954BAA24}"

Private Const NET_FX_10_SPx_REG_KEY_VALUE As String = "Version"

Private Const NET_FX_11_REG_KEY_NAME As String = _

"Software\Microsoft\NET Framework Setup\NDP\v1.1.4322"

Private Const NET_FX_11_SPx_REG_KEY_NAME As String = _

"Software\Microsoft\NET Framework Setup\NDP\v1.1.4322"

Private Const NET_FX_11_REG_KEY_VALUE As String = "Install"

Private Const NET_FX_11_SPx_REG_KEY_VALUE As String = "SP"

Sub Main()

Dim message As String

Dim netfx10SPLevel As Integer = -1

Dim netfx11SPLevel As Integer = -1

' Determine whether or not the .NET Framework 1.0 or 1.1 are installed

Dim netfx10Installed As Boolean = IsNetfx10Installed()

Dim netfx11Installed As Boolean = IsNetfx11Installed()

' If .NET Framework 1.0 is installed, get the service pack level

Console.WriteLine(".NET Framework 1.0")

Console.WriteLine(
"------------------")

If (netfx10Installed) Then

netfx10SPLevel = GetNetfx10SPLevel()

If (netfx10SPLevel > 0) Then

message = String.Format(".NET Framework 1.0 SP{0} is installed.", netfx10SPLevel)

Else

message = ".NET Framework 1.0 is installed with no service packs."

End If

Console.WriteLine(message)

Else

Console.WriteLine(".NET Framework 1.0 is not installed.")

End If

Console.WriteLine()

' If .NET Framework 1.1 is installed, get the service pack level

Console.WriteLine(".NET Framework 1.1")

Console.WriteLine(
"------------------")

If netfx11Installed Then

netfx11SPLevel = GetNetfx11SPLevel()

If netfx11SPLevel > 0 Then

message = String.Format(".NET Framework 1.1 SP{0} is installed.", netfx11SPLevel)

Else

message = ".NET Framework 1.1 is installed with no service packs."

End If

Console.WriteLine(message)

Else

Console.WriteLine(".NET Framework 1.1 is not installed.")

End If

Console.WriteLine()

Console.WriteLine(
"Press [enter] to continue.")

Console.Read()

Environment.ExitCode = 0

End Sub



''' <COMMENT>

''' Description: Uses the detection method recommended at

''' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetdep/html/dotnetfxref.asp

''' to determine whether the .NET Framework 1.0 is installed on the machine

''' Inputs: None

''' Results: True if the .NET Framework 1.0 is installed, False otherwise

''' </COMMENT>

Function IsNetfx10Installed() As Boolean

D
im key As RegistryKey = Registry.LocalMachine.OpenSubKey(NET_FX_10_REG_KEY_NAME, False)

Dim value As String = CType(key.GetValue(NET_FX_10_REG_KEY_VALUE, ""), String)

key.Close()

Return (value.Length > 0)

End Function



''' <COMMENT>

''' Description: Uses the detection method recommended at

''' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetdep/html/redistdeploy1_1.asp

''' to determine whether the .NET Framework 1.1 is installed on the machine

''' Inputs: None

''' Results: True if the .NET Framework 1.1 is installed, False otherwise

''' </COMMENT>

Function IsNetfx11Installed() As Boolean

Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey(NET_FX_11_REG_KEY_NAME, False)

Dim value As Integer = CType(key.GetValue(NET_FX_11_REG_KEY_VALUE, 0), Integer)

key.Close()

Return (value = 1)

End Function

''' <COMMENT>

''' Description: Uses the detection method recommended at

''' http://blogs.msdn.com/astebner/archive/2004/09/14/229802.aspx

''' to determine what service pack for the .NET Framework 1.0 is installed on the machine

''' Inputs: None

''' Results: Integer representing SP level for .NET Framework 1.0

''' </COMMENT>

Function GetNetfx10SPLevel() As Integer

Dim pszSPLevel As String = Nothing

Dim result As Integer = -1

' Need to detect what OS we are running on so we know what registry key

' to use to look up the SP level.

Dim key As RegistryKey

If IsCurrentOSTabletMedCenter() Then

key = Registry.LocalMachine.OpenSubKey(NET_FX_10_SPx_OCM_REG_KEY_NAME, False)

Else

key = Registry.LocalMachine.OpenSubKey(NET_FX_10_SPx_MSI_REG_KEY_NAME, False)

End If

Dim value As String = CType(key.GetValue(NET_FX_10_SPx_REG_KEY_VALUE, ""), String)

key.Close()

If value.Length > 0 Then

' This registry value should be of the format #,#,#####,# where the last # is the SP level.

' We are just interested in the #.

Dim values() As String = Split(value, ",")

If values.Length = 4 Then

Return CInt(values(3))

End If

End If

Return result

End Function



''' <COMMENT>

''' Description: Uses the detection method recommended at

''' http://blogs.msdn.com/astebner/archive/2004/09/14/229574.aspx

''' to determine what service pack for the .NET Framework 1.1 is installed on the machine

''' Inputs: NONE()

''' Results: Integer representing SP level for .NET Framework 1.1

''' </COMMENT>

Function GetNetfx11SPLevel() As Integer

Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey(NET_FX_11_SPx_REG_KEY_NAME, False)

Dim value As Integer = CType(key.GetValue(NET_FX_11_SPx_REG_KEY_VALUE, -1), Integer)

key.Close()

Return value

End Function


Function IsCurrentOSTabletMedCenter() As Boolean
' Use GetSystemMetrics to detect if we are on a Tablet PC or Media Center OS

Return (GetSystemMetrics(SM_TABLETPC) <> 0 OrElse GetSystemMetrics(SM_MEDIACENTER) <> 0)

End Function

End
Module

 
Joined
Jan 3, 2005
Messages
10
Location
KY, USA
Programming Experience
1-3
I think what I need is in the Installer, which checks to see if .Net Framework is installed. Does anyone know where I can get cheap or free installer programs that might do that?
 
Top Bottom