Welcome, Guest
Username: Password: Remember me
Share your code snippets, screen shots etc. here
  • Page:
  • 1

TOPIC:

Retrieve current installed .NET version 30 Jul 2018 11:53 #5657

  • wriedmann
  • wriedmann's Avatar
  • Topic Author


  • Posts: 3366
  • 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
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    Retrieve current installed .NET version 30 Jul 2018 18:49 #5661

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • 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.

    Retrieve current installed .NET version 30 Jul 2018 19:46 #5663

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3366
  • 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
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    Retrieve current installed .NET version 30 Jul 2018 20:20 #5665

    • Chris
    • Chris's Avatar


  • Posts: 3982
  • 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.

    Retrieve current installed .NET version 30 Jul 2018 21:05 #5667

    • wriedmann
    • wriedmann's Avatar
    • Topic Author


  • Posts: 3366
  • 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
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

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

    • Page:
    • 1