I have created a script which detects installed .Net Framework installed through registry. The condition should specifically detect 3.5 or higher version and continue the process. However, using the registry it seems not possible. Every time there is a new version installed, you have to search and input the registry or modify the script just to make it works.
Then I searched it up on google that it can be done through WMI and this seems gonna work. I have modified the script to be flexible even though there are new installed .net framework higher than 3.5 it will automatically detect 3.5 or higher version installed. Unfortunately, one condition is not working if the scripts detect that there is lower version or no installed .net framework installed, the script should quit and will not continue the process.
WriteLog "Checking if there is .Net Framework 4.5, .Net Framework 4.0 and .Net Framework 3.5 installed on the machine.."
If ((RegValueExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{8E34682C-8118-31F1-BC4C-98CD9675E1C2}\")) AND (RegValueExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{F5B09CFD-F0B2-36AF-8DF4-1DF6B63FC7B4}\"))) Then
WriteLog"Framework 4 detected on system. "
WriteLog "Proceeding with installation..."
ElseIf FrameworkCheck("3.5") Then
'Proceed with installation
End If
Function FrameworkCheck
Function FrameworkCheck(strVersion)
Dim strComputer, objWMIService, colItems, strVar, objItem
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name, Version from Win32_Product Where Name Like 'Microsoft .NET Framework%'")
For Each objItem in colItems
If objItem.Version => strVersion Then
WriteLog "Detected Framework Version: " & objItem.Version & " - " & objItem.Name
WriteLog "Proceeding with installation..."
ElseIf objItem.Version <> 0 Then
WriteLog "NOK-Framework 3.5 or later not detected on system. Installation not possible. Please check basic client installation"
WScript.Quit(-1)
End If
Next
End Function