#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=S:\SISCO\MKT\GRAPHICS\Icons\SISCO.ico
#AutoIt3Wrapper_Outfile=GetDotNetVersions.exe
#AutoIt3Wrapper_UseUpx=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; ==========================================================================================================================
; Func _dotNetGetVersions($bOnlyInstalled=False)
;
; Function to return information on which .NET versions are/were installed.
; NOTES: No Service Pack information is retrieved, although that can be obtained using the methods
; in the MSDN link below.
;
; Also NOTE: As with anything I program (in full or part), keep the header WITH the function if used or shared.
;
; .NET Framework detection resource:
; MSDN KB318785: 'How to determine which versions and service pack levels of the Microsoft .NET Framework are installed':
; @ http://msdn.microsoft.com/en-us/kb/kbarticle.aspx?id=318785
;
; $bOnlyInstalled = If True, it will not report on any versions that were uninstalled
;
; Returns:
; Success: An array of information, as follows:
; [0][0] = Total # found
; [x][0] = Numerical version (can be whole number or floating point [1, 1.1, 2, 3, 3.5, 4])
; [x][1] = Full version name string - this can be used to probe further sub-version info (example: "v2.0.50727")
; [x][2] = 0 or 1 - indicates whether 'client' or normal installation is installed
; (From version 4+, there can be a client and/or a full install - though full seems to install client.)
; [x][3] = 0 or 1 - indicates whether 'full' install of the .NET component is installed (version 4+ only)
; Failure: '' and @error set:
; @error = -3 = .NET key could not be read, or .NET is not installed (the latter *most* likely)
; (@extended returns @error state from last Reg* call.)
;
; ==========================================================================================================================
Func _dotNetGetVersions($bOnlyInstalled=False)
Local $i=1,$iClientInstall,$iFullInstall,$iNum,$aVersions[100][4],$iTotal=0,$bVer4Found=0
Local $sKey="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP",$sSubKey
; Detect v1.0 (special key)
RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\Policy\v1.0","3705")
; If value was read (key exists), and is of type REG_SZ (1 as defined in ), v1.0 is installed
If @error=0 And @extended=1 Then
$iTotal+=1
$aVersions[$iTotal][0]=1.0
$aVersions[$iTotal][1]='v1.0.3705'
$aVersions[$iTotal][2]=1
$aVersions[$iTotal][3]=1
EndIf
While 1
$iClientInstall=0
$iFullInstall=0
$sSubKey=RegEnumKey($sKey,$i)
If @error Then ExitLoop
$i+=1
; 'v4.0' is a deprecated version. Since it comes after 'v4' (the newer version) while enumerating,
; a simple check if 'v4' has already been found is sufficient
If $sSubKey='v4.0' And $bVer4Found Then ContinueLoop
$iNum=Number(StringMid($sSubKey,2)) ; cuts off at any 2nd decimal points (obviously)
; Note - one of the SubKeys is 'CDF'. Number() will return 0 in this case [we can safely ignore that]
If $iNum=0 Then ContinueLoop
;~ ConsoleWrite(".NET Framework SubKey #"&$i&": "&$sSubKey&", Number extracted (0 for non-versioned items):"&$iNum&@LF)
If $iNum<4 Then
$iClientInstall=RegRead($sKey&'\'&$sSubKey,'Install')
If $iClientInstall Then $iFullInstall=1 ; older versions were all-or-nothing I believe
;~ If @error Then $iClientInstall=0 ; (@error from $iClientInstall) -> caught below
Else
; Version 4 works with one or both of these keys. One can only hope new versions keep the same organization
$iFullInstall=RegRead($sKey&'\'&$sSubKey&'\Full','Install')
If @error Then $iFullInstall=0
$iClientInstall=RegRead($sKey&'\'&$sSubKey&'\Client','Install')
;~ If @error Then $iClientInstall=0 ; Caught below
If $iNum<5 Then $bVer4Found=True
EndIf
If @error Then $iClientInstall=0
If $bOnlyInstalled And $iClientInstall=0 And $iFullInstall=0 Then ContinueLoop
$iTotal+=1
$aVersions[$iTotal][0]=$iNum
$aVersions[$iTotal][1]=$sSubKey
$aVersions[$iTotal][2]=$iClientInstall
$aVersions[$iTotal][3]=$iFullInstall
WEnd
If $iTotal=0 Then Return SetError(-3,@error,'')
$aVersions[0][0]=$iTotal
ReDim $aVersions[$iTotal+1][4]
Return $aVersions
EndFunc
; ------- TEST ----------
#include
$adotNetVersions=_dotNetGetVersions()
$adotNetVersions[0][0]="Main Version #"
$adotNetVersions[0][1]="Full version string"
$adotNetVersions[0][2]="Client/General Install?"
$adotNetVersions[0][3]="Full Install?"
If (@OSVersion = "WIN_2012R2" Or @OSVersion = "WIN_2008R2" Or @OSVersion = "WIN_10" Or @OSVersion = "WIN_2016") Then
$iIndex = _ArrayBinarySearch($adotNetVersions, "v3.5", 0, 0, 1)
If ($iIndex < 1) Then
MsgBox($MB_SYSTEMMODAL, "GetDotNetVersions", "Setup has detected that Microsoft's .NET Framework 3.5 is not installed on this computer. This must be installed using the Server Manager by adding the .NET 3.5 Feature prior to running Setup. Setup will now exit.")
SetError(1) ;
EndIf
ElseIf (@OSVersion = "WIN_10") Then
MsgBox($MB_SYSTEMMODAL, "GetDotNetVersions", "Setup has detected that Microsoft's .NET Framework 3.5 is not installed on this computer. This can be installed using Programs and Features->Add Windows Component and chosing the .NET 3.5 Feature prior to running Setup. Setup will now exit.")
SetError(1) ;
EndIf
_ArrayDisplay($adotNetVersions,'.NET versions')