xsharp.eu • Retrieve current installed .NET version
Page 1 of 1

Retrieve current installed .NET version

Posted: Mon Jul 30, 2018 9:53 am
by wriedmann
Hello,

to retrieve the current version of the .NET Framework, you can use this code:

Code: Select all

function GetLatestVersion4() as string
	local cReturn as string
	local oMainKey as RegistryKey
	local oKey as RegistryKey
	local nClientRelease as int
	local nFullRelease as int
	local cClientVersion as string
	local cFullVersion as string
	local nRelease as int
	local cVersion as string
	
	cReturn := ""
	
	oMainKey	 := RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, RegistryView.Default )
	oKey := oMainKey:OpenSubKey( "SOFTWAREMicrosoftNET Framework SetupNDPv4Client" ) 
	nClientRelease := ( int ) oKey:GetValue( "Release", 0 )
	cClientVersion := ( string ) oKey:GetValue( "Version", "" )
	oKey:Dispose()
	oKey := null
	
	oKey := oMainKey:OpenSubKey( "SOFTWAREMicrosoftNET Framework SetupNDPv4Full" ) 
	nFullRelease := ( int ) oKey:GetValue( "Release", 0 )
	cFullVersion := ( string ) oKey:GetValue( "Version", "" )
	oKey:Dispose()
	oKey := null
	oMainKey:Dispose()
	oMainKey := null
	
	if nFullRelease > nClientRelease
		nRelease := nFullRelease
	else	
		nRelease := nClientRelease
	endif
	if cFullVersion > cClientVersion
		cVersion := cFullVersion
	else	
		cVersion := cClientVersion
	endif
	
	do case
	case nRelease == 0
		cReturn := cVersion
	case nRelease == 378389
		cReturn := ".NET Framework 4.5"
	case nRelease == 378675
		cReturn := ".NET Framework 4.5.1 - Windows 8.1"
	case nRelease == 378758
		cReturn := ".NET Framework 4.5.1 - Windows 8, Windows 7 SP1, Windows Vista SP2"
	case nRelease == 379893
		cReturn := ".NET Framework 4.5.2"
	case nRelease == 393295
		cReturn := ".NET Framework 4.6 - Windows 10"
	case nRelease == 393297
		cReturn := ".NET Framework 4.6 - other"
	case nRelease == 394254
		cReturn := ".NET Framework 4.6.1 - Windows 10"
	case nRelease == 394271
		cReturn := ".NET Framework 4.6.1 - other"
	case nRelease == 394802
		cReturn := ".NET Framework 4.6.2 - Windows 10 Anniversary Update"
	case nRelease == 394806
		cReturn := ".NET Framework 4.6.2 - other"
	case nRelease == 460798
		cReturn := ".NET Framework 4.7 - Windows 10 Creators Update"
	case nRelease == 460805
		cReturn := ".NET Framework 4.7 - other"
	case nRelease == 461308
		cReturn := ".NET Framework 4.7.1 - Windows 10 Fall Creators Update"
	case nRelease == 461310
		cReturn := ".NET Framework 4.7.1 - other"
	case nRelease == 461808
		cReturn := ".NET Framework 4.7.2 - Windows 10 April 2018 Update"
	case nRelease == 461814
		cReturn := ".NET Framework 4.7.2 - other"
	otherwise
		cReturn := ".NET Framework " + nRelease:ToString()
	endcase

	return cReturn
You can find a complete application as XIDE export file with this code here:
GetDotNETVersion.zip
(16.92 KiB) Downloaded 140 times
Wolfgang

Retrieve current installed .NET version

Posted: Mon Jul 30, 2018 4:49 pm
by Karl-Heinz
Hi Wolfgang,

work´s fine.

win 8.1 -> ".NET Framework 4.7.2 - other"
Win10 -> ".NET Framework 4.7.2 - Windows 10 April 2018 Update"

BTW. What´s the reason why your viaef references do not point to the GAC ?

regards
Karl-Heinz

Retrieve current installed .NET version

Posted: Mon Jul 30, 2018 5:46 pm
by wriedmann
Hi Karl-Heinz.

very simple: if I use the references from the GAC, this application will not run on all .NET 4 versions.

I have built it with v4.0 references, so it will run even on Windows XP (where no .NET 4.5 is available, only 4.0).

Wolfgang

Retrieve current installed .NET version

Posted: Mon Jul 30, 2018 6:20 pm
by Chris
Hi Wolfgang.

I think it should always work if you have GAC references. Have you found a specific case where this does not work?

Chris

Retrieve current installed .NET version

Posted: Mon Jul 30, 2018 7:05 pm
by wriedmann
Hi Chris,

no, when using the GAC references it does not run under Windows XP and not under Windows installations that don't have the latest .NET Framework (had issues with a customer on a Win 7 machine where for two year no update was installed).

Wolfgang