Ed The Dev .com

Edward Delaporte's Technical Journal

Use VBScript to Detect If .Net 2 is Installed

no comment

Coding against the .Net 2.0 framework gives a healthy number of substantial advantages; but when you’re deploying to unknown machines, you need a way to tell whether .Net 2.0 is installed; without relying on .Net 2.0 to do the detection itself.

So without further ado, I present a quick VBScript that can do that for you.

set shell = WScript.CreateObject("WScript.Shell")
sysRoot = shell.ExpandEnvironmentStrings("%systemroot%")
' sysRoot = shell.ExpandEnvironmentStrings("%windir%")
path = sysRoot + "\Microsoft.NET\Framework"
set fs = CreateObject("Scripting.FileSystemObject")
GotDotNet2 = False
On Error Resume Next
set folder = fs.GetFolder(path)
If Err = 0 Then
Set re = new regexp
re.Pattern = "^v2"
For each item in folder.SubFolders
If re.Test(item.Name) Then
GotDotNet2 = True
' Msgbox item.Name
End If
Next
End If
Msgbox GotDotNet2

Naturally, you might choose to do something with the value in ‘GotDotNet2′, rather than displaying it.

Enjoy!

  • Edward

Leave a Reply

You must be logged in to post a comment.