can you share a vbscript which checks if .NET 2.0 is installed on a machine.
I did a search on the web and the most of the such "check if .net is installed" applications are just look up for a particular registry keys thus ignoring the fact the the installation could be corrupted.
Basically I am looking for script which tries to create a .NET object (which should be surely createable - e.g. System.Object) and if it failes - .NET either is not installed or the installation is corrupted (thus no better than having no .NET installed at all).
The official way to detect if a particular version of the .NET Framework is installed is by checking for the existence of the corresponding registry key. In this case, you're looking for this key:
If the REG_SZ value "50727" is present, then 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:
If you're wanting to integrate this check into an existing VBScript, I suggest that you turn it into a function that returns a
Boolean
value (instead of displaying a message box) depending on whether or not the proper version of the .NET Framework is installed. Then you can call this function from within your script. Note: Make sure that you turn the error handling back off (or at least back to a more appropriate style) at the end of the function if you go this route! You don't want to be usingOn Error Resume Next
unless you're explicitly handling the errors later in your code.EDIT: If you are convinced that you want to determine the validity of a .NET installation by trying to instantiate a common framework object, the script is very similar. (In fact, it's even a little simpler than doing registry access.) As before,
CreateObject
is used, but this time to instantiate an object of the base classSystem.Object
:However, this will not tell you which version of the .NET Framework is installed. This test will pass for any version, including 1.1, 2.0, 4.0, future versions, etc. Your question seemed to state a requirement for version 2.0, and if that's the case, you really should consider using the first option.
My experience has been that such "corrupted" installations of the Framework are extremely rare, and if you're seeing them as often as I'm led to believe, you might consider just installing the proper version of the Framework as a matter of course. I'm unconvinced that being able to instantiate an object of type
System.Object
is really any more of a "true" test of the validity of the Framework installation than checking for the presence of Registry keys or directories.This has now been tested to work on a clean Windows XP virtual machine without the .NET Framework installed. It correctly reports failure. On other machines with the .NET Framework installed, it correctly reports success.
The best option to know if .NET FRAMEWORK 2 is installed properly I would recommend to make a script that look for "2 THINGS";
Check if the RegKey is still there, like 'Cody Gray' showed.
I would write a code that checks if NET FRAMEWORK 2 (located on the Windows directory) is smaller than for example 75 MB (which normally is around 82 -87 MB ), if so than its either uninstalled or damaged.
by putting these 2 codes together you'll be able to know if NET FRAMEWORK 2 is correctly installed on the users machine or not
This works as well and is an exact copy off of the MSDN website of recomended ways to test .net installation.
Website - http://support.microsoft.com/kb/318785/en-us