Aaargh. In testing my Help Builder install on a fresh XP machine today that has the .NET framework installed, but not ASP.NET I realized that the auto-registration of the .NET COM interop assemblies isn’t working. The reason for this is some code I use to try and detect the .NET framework directory so I can dynamically execute RegAsm and register the wwReflection assembly for COM interop.
My previous code was twisted enough – it truly boggles the mind that Microsoft did not see fit to have a couple of simple registry keys, that tell you which version is installed and where each of these versions lives on disk so you can access the various utilities.
Oh there are registry keys alright. There are keys that say this version is installed (the latest). One will tell you the detail, another will give you the major version and yet another might at the Windows path for the main .NET directory (thanks – that’s real useful!). Well, there’s one key:
HKEY_LOCAL_MACHINE,"Software\Microsoft\ASP.Net
RootVer
That tells me exactly what I need which is the last version installed. From there you can look at that entry (with some modification and stripping) and get the framework path.
HKEY_LOCAL_MACHINE,"Software\Microsoft\ASP.Net\"+lcVersion,"PATH")
Unfortunately I didn’t realize that the RootVer key does not get set unless ASP. Net is actually registered (ASPNET_IISREG.EXE), which means the machine had to have IIS installed when .NET got installed or ASPNET_IISREG.EXE had to be run afterwards to hook up the script maps and client script folders for ASP.NET.
So, back to the drawing board - sort of. I took a brute force approach: if the RootVer key is not there by looking for specific versions of the framework explicitly.
************************************************************************
* wwUtils :: IsDotNet
****************************************
*** Function: Returns whether .Net is installed
*** Optionally returns the framework path and version
*** of the highest installed version.
************************************************************************
FUNCTION IsDotNet(lcFrameworkPath,lcVersion)
LOCAL loAPI as wwAPI
lcVersion = ""
lcFrameworkPath = ""
loAPI = CREATEOBJECT("wwAPI")
lcWinDir = loAPI.getSystemdir(.t.)
lcVersion = loAPI.Readregistrystring(HKEY_LOCAL_MACHINE,"Software\Microsoft\ASP.Net","RootVer")
IF ISNULL(lcVersion)
*** If ASP.NET is not registered RootVer is not set
*** we need a different way: probe for specific versions
lcVersion = "1.1.4322.0"
lcFrameWorkPath = loAPI.Readregistrystring(HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\ASP.NET\1.1.4322.0","Path")
IF ISNULL(lcFrameworkPath)
lcVersion = "v1.0.3705.0"
lcFrameWorkPath = loAPI.Readregistrystring(HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\ASP.NET\v1.0.3705.0","Path")
IF ISNULL(lcFrameworkPath)
*** December CTP
lcVersion = "v2.0.40607.0"
lcFrameWorkPath = loAPI.Readregistrystring(HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\ASP.NET\v2.0.40607.0","Path")
ENDIF
ENDIF
IF ISNULL(lcFrameworkPath)
lcFrameworkPath = ""
ELSE
lcFrameworkPath = ADDBS( lcFrameworkPath )
ENDIF
RETURN .T.
ENDIF
*** Strip of the build number and replace with 0
lnAt = AT(".",lcVersion,3)
IF lnAt > 0
lcVersion = SUBSTR(lcVersion,1,lnAt) + "0"
ENDIF
lcFrameworkPath = loAPI.Readregistrystring(HKEY_LOCAL_MACHINE,"Software\Microsoft\ASP.Net\"+lcVersion,"PATH")
IF ISNULL(lcFrameworkPath)
lcFrameworkPath = ""
ELSE
lcFrameworkPath = ADDBS(lcFrameworkPath)
ENDIF
RETURN .T.
ENDFUNC
* wwUtils :: IsDotNet
This is not what I would call an ideal situation but it appears to work well. Now I only have to remember to update the version number once new versions of .NET ship. Obviously all the intermediate CTP versions are probably not required here, but when 2.0 ships that definitely would need to go in there probably as the primary check.
The brute force approach has some problems – namely you won’t really know if the version is the primary version installed. I’m not 100% sure, but I think that if you uninstall a .NET version it doesn’t completely wipe out registry keys so that may be a problem as well.
Another alternative I was thinking about was to look in the Windows\Microsoft.NET directory. All versions are listed in there in a specific format, but that gets tricky too as well because again you have to worry about uninstalls not completely clearing the dirs (and then you have to look for specific files) and no way of knowing which is the last installed version.
This all seems pretty silly – a couple of simple registry keys from Microsoft would have solved this problem nicely.
Other Posts you might also like