fbpx
× Share your code snippets, screen shots etc. here

Retrieve current installed .NET version

  • Wolfgang Riedmann
  • Wolfgang Riedmann's Avatar Topic Author
  • Offline
More
5 months 2 weeks ago #1 by Wolfgang Riedmann
Retrieve current installed .NET version was created by Wolfgang Riedmann
Hello,

to retrieve the current version of the .NET Framework, you can use this code:
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( "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client\" ) 
	nClientRelease := ( int ) oKey:GetValue( "Release", 0 )
	cClientVersion := ( string ) oKey:GetValue( "Version", "" )
	oKey:Dispose()
	oKey := null
	
	oKey := oMainKey:OpenSubKey( "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" ) 
	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:

File Attachment:

File Name: GetDotNETVersion.zip
File Size:17 KB


Wolfgang
Attachments:

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #2 by Karl-Heinz Rauscher
Replied by Karl-Heinz Rauscher on topic Retrieve current installed .NET version
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

Please Log in or Create an account to join the conversation.

  • Wolfgang Riedmann
  • Wolfgang Riedmann's Avatar Topic Author
  • Offline
More
5 months 2 weeks ago #3 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Retrieve current installed .NET version
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

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #4 by Chris Pyrgas
Replied by Chris Pyrgas on topic Retrieve current installed .NET version
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

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Wolfgang Riedmann
  • Wolfgang Riedmann's Avatar Topic Author
  • Offline
More
5 months 2 weeks ago #5 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Retrieve current installed .NET version
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

Please Log in or Create an account to join the conversation.