The official way to determine if a particular version of the .NET Framework is installed is to check for the presence of an appropriate registry key. In this case, you are looking for this key:
HKLM\SOFTWARE\Microsoft\.NETFramework\Policy\v2.0
If REG_SZ value "50727" is present, you know that version 2.0 of the Framework is installed.
So how do you do this in VBScript? Here's a little script that does just that:
Option Explicit Dim oShell Dim value ''
If you want to integrate this check into existing VBScript, I suggest you turn it into a function that returns a Boolean value (instead of displaying a message box) depending on whether the correct version was installed by the .NET Framework. Then you can call this function from your script. Note. Make sure you return error handling (or at least back to a more appropriate style) at the end of the function if you go this route! You do not want to use On Error Resume Next unless you explicitly handle errors later in your code.
On Error Goto 0 ''
EDIT: If you are sure you want to determine if the .NET installation is correct by trying to instantiate a common frame object, the script is very similar. (Actually, this is even a little easier than accessing the registry.) As before, CreateObject used, but this time to create an object of the base class System.Object :
On Error Resume Next Dim testObj Set testObj = CreateObject("System.Object") If Err.Number = 0 Then MsgBox("Success") Else MsgBox("Failure") End If
However, this will not tell you which version of the .NET Framework is installed. This test will pass for any version, including versions 1.1, 2.0, 4.0, future versions, etc. Your question allegedly states a requirement for version 2.0, in which case you really should consider using the first option.
My experience is that such “damaged” Framework installations are extremely rare, and if you see them as often as it seems to me, you can simply install the correct version of the Framework for granted. I am not convinced that the possibility of creating an instance of an object of type System.Object really no longer a “true” test of the validity of the Framework installation, than a check for the presence of registry keys or directories.
This is now tested to work on a clean Windows XP virtual machine without the .NET Framework installed. It correctly reports an error. On other computers with the .NET Framework installed, it correctly reports success.