Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

How can I detect if .NET has been installed?


3 replies to this topic

TobiasEriksson

TobiasEriksson
  • Members
  • 16 posts

Posted 06 April 2004 - 07:56

I need to detect whether the .NET framework has been installed on the machine allready. We require that version 1.1.xxxx is installed, and therefore it is also important to know the version.

There just have to be tons of installers where one wants to detect .NET, but I haven't come around any good solutions.

The only thing I could think of is to check for the .NET install path in the Registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\InstallRoot

and then look inside that dir for directories with version numbers, and then try to figure out the version from there.

Does anyone else has any good solutions, perhaps the version of some DLL might give me that information?

Regards
Tobias


TobiasEriksson

TobiasEriksson
  • Members
  • 16 posts

Posted 06 April 2004 - 13:02

This is what I have come up to, using the registry and .NET-folder name information:

' ********************************************
'
' CheckForDOTNET
'
' This function checks if the .NET package is installed
' it will set the property NO_DOTNET = "true" if it can not be found
'
' ********************************************
Function CheckForDOTNET()
CheckForDOTNET = 1
DefaultUIFont = Session.Property( "DefaultUIFont" )
'
' We start with the assumption that it is not installed
'
Property( "NO_DOTNET" ) = "true"
Property( "DOTNET_VERSION" ) = "N/A"
Property( "DOTNET_TEXT" ) = DefaultUIFont + "Microsoft .NET Framework v1.1+ is required to run the application (not found)."
bVersionFound = 0

On Error Resume Next
Err.Clear
'
' Find the installation-path of the .NET package in the Registry
'
Set WshShell = CreateObject("WScript.Shell")
sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\InstallRoot"
sRootPath = WshShell.RegRead( sKey )
If Err.Number <> 0 Then
' Failed to access registry
Exit Function
End If
'
' Now we have the path, but we need to know what version has been installed
' so we are looking for the version-directories e.g. 1.0.xxx or 1.1.xxxx
' the version we support is 1.1.xxxx and up
'
Set regEx = new RegExp
regEx.Pattern = "^v(1\.[1-9]|[2-9]\.[0-9])"
regEx.IgnoreCase = True
Set rFSO = CreateObject("Scripting.FileSystemObject")
If NOT rFSO.FolderExists( sRootPath ) Then
' The folder does not exist
Exit Function
End If
Set rFolder = rFSO.GetFolder(sRootPath)
Set rSubFolders = rFolder.SubFolders

For Each rAFolder in rSubFolders
If regEx.Test( rAFolder.name ) Then
' Found the right folder, i.e. with the right version
Property( "NO_DOTNET" ) = "false"
Property( "DOTNET_VERSION" ) = rAFolder.name
Property( "DOTNET_TEXT" ) = DefaultUIFont + "Microsoft .NET Framework v1.1+ is required to run the application (" & rAFolder.name & " found)."
bVersionFound = 1
Exit For
End If
Next
End Function

TobiasEriksson

TobiasEriksson
  • Members
  • 16 posts

Posted 06 April 2004 - 13:07

Alternatively you could take a peek at the built in property; MsiNetAssemblySupport and look at the version there instead.
Altough this PROPERTY will not be updated unless you restart the installer. If that is OK then this should be sufficient.


' ********************************************
'
' CheckForDOTNET
'
' This function checks if the .NET package is installed
' it will set the property NO_DOTNET = "true" if it can not be found
'
' ********************************************
Function CheckForDOTNET()
Dim regEx
'
' Set return value of function, in this case allways return 1 as in success, otherwise the installer want continue ' Set return value of function
'
CheckForDOTNET = 1

'
' See if the .NET property has been set
'
DOTNETProperty = Session.Property( "MsiNetAssemblySupport" )
DefaultUIFont = Session.Property( "DefaultUIFont" )

If Len( trim( DOTNETProperty ) ) < 1 Then
'
' Let the installer know that the object was NOT found
'
Property( "NO_DOTNET" ) = "true"
Property( "DOTNET_VERSION" ) = "N/A"
Property( "DOTNET_TEXT" ) = DefaultUIFont + "Microsoft .NET Framework v1.1 or above is required to run the application (not found)."
Else
'
' Let the installer know that .NET was installed
'
DOTNET_VERSION = trim( DOTNETProperty )
Property( "DOTNET_VERSION" ) = DOTNET_VERSION
Set regEx = new RegExp
regEx.Pattern = "^([2-9]\.|1\.[1-9])"
regEx.IgnoreCase = True
If regEx.Test( DOTNET_VERSION ) Then
Property( "NO_DOTNET" ) = "false"
Else
Property( "NO_DOTNET" ) = "true"
End If
Property( "DOTNET_TEXT" ) = DefaultUIFont + "Microsoft .NET Framework is required to run the application (v"+DOTNET_VERSION+" found)."
End If
End Function


Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 10 April 2004 - 17:06

I think other tools just look for mscoree. Probably there's some documentation in MSDN.