Deployment Solution

 View Only

Detecting which .NET Frameworks are installed using VBScript 

May 05, 2011 01:13 PM

The code developed for this article is based on a Microsoft technote which can be found here: http://msdn.microsoft.com/en-us/kb/kbarticle.aspx?id=318785

The VB Script code that follows was designed to be used as a custom action in an MSI package. The final line, which is remarked out, will display a summary of installed frameworks if you wish to use the script as a manual check tool.

Dim WshShell, mKey, nKey, oKey
Dim net40clientInstall, net40clientSP
Dim net40fullInstall, net40fullSP
Dim net35Install, net35SP
Dim net30Install, net30SP
Dim net20Install, net20SP
Dim net11Install, net11SP
Dim net10Install, net10SP
Dim net10InstallMedia, net10SPMedia
Dim CRLF
CRLF= chr(10)&chr(13)
Set WshShell = CreateObject("WScript.Shell") 
mKey="HKLM\Software\Microsoft\"
nKey=mKey & "NET Framework Setup\NDP\"
oKey=mKey & "Active Setup\Installed Components\"

On error resume next

net40clientInstall = "Not Found"
net40clientSP = "Not Found"
net40clientInstall = WshShell.RegRead(nKey & "v4\client\Install")
net40clientSP = WshShell.RegRead(nKey & "v4\client\Version")
Session.Property("N40CLIENT") = CStr(net40clientSP)

net40fullInstall = "Not Found"
net40fullSP = "Not Found"
net40fullInstall = WshShell.RegRead(nKey & "v4\full\Install")
net40fullSP = WshShell.RegRead(nKey & "v4\full\Version")
Session.Property("N40FULL") = CStr(net40fullSP)

net35Install = "Not Found"
net35SP = "Not Found"
net35Install = WshShell.RegRead(nKey & "v3.5\Install")
net35SP = WshShell.RegRead(nKey & "v3.5\SP")
Session.Property("N35") = CStr(net35SP)    

net30Install = "Not Found"
net30SP = "Not Found"
net30Install = WshShell.RegRead(nKey & "v3.0\Install")
net30SP = WshShell.RegRead(nKey & "v3.0\SP")
Session.Property("N30") = CStr(net30SP)

net20Install = "Not Found"
net20SP = "Not Found"
net20Install = WshShell.RegRead(nKey & "v2.0.50727\Install")
net20SP = WshShell.RegRead(nKey & "v2.0.50727\SP")
Session.Property("N20") = CStr(net20SP)

net11Install = "Not Found"
net11SP = "Not Found"
net11Install = WshShell.RegRead(nKey & "v1.1.4322\Install")
net11SP = WshShell.RegRead(nKey & "v1.1.4322\SP")
Session.Property("N11") = CStr(net11SP)

net10Install = "Not Found"
net10SP = "Not Found"
net10Install = WshShell.RegRead(oKey & "{78705f0d-e8db-4b2d-8193-982bdda15ecd}\Version")
If Trim(net10Install) = "1.0.3705.0" then net10SP = "0"
If Trim(net10Install) = "1.0.3705.1" then net10SP = "1"
If Trim(net10Install) = "1.0.3705.2" then net10SP = "2"
If Trim(net10Install) = "1.0.3705.3" then net10SP = "3"
Session.Property("N10") = CStr(net10SP)

net10InstallMedia = "Not Found"
net10SPMedia = "Not Found"
net10InstallMedia = WshShell.RegRead(oKey & "{FDC11A6F-17D1-48f9-9EA3-9051954BAA24}\Version")
If Trim(net10InstallMedia) = "1.0.3705.2" then net10SPMedia = "2"
If Trim(net10InstallMedia) = "1.0.3705.3" then net10SPMedia = "3"
Session.Property("N10MEDIA") = CStr(net10SPMedia)

'WScript.Echo "net40clientInstall: " & net40clientInstall &"   net40clientSP: "& net40clientSP &CRLF& "net40fullInstall: " & net40fullInstall &"   net40fullSP: "& net40fullSP &CRLF&  "net35Install: " & net35Install &"   net35SP: "& net35SP &CRLF& "net30Install: " & net30Install &"   net30SP: "& net30SP &CRLF& "net20Install: " & net20Install &"   net20SP: "& net20SP &CRLF& "net11Install: " & net11Install &"   net11SP: "& net11SP &CRLF& "net10Install: " & net10Install &CRLF&  "net10InstallMedia: " & net10InstallMedia

CODE NOTES

1. The line Set WshShell = CreateObject("WScript.Shell") may need to be amended to
Set WshShell = Wscript.CreateObject("WScript.Shell") for manual execution. The form used here is as required for use in an MSI custom action.

2. The CStr function is required as the registry values retrieved in many cases are DWORD rather than string values, so it is necessary to convert them to string values in order for Session.property to work correctly.

3. The final Wscript.Echo line can of course be deleted if using as a custom action. It is there only in case of manual use.

4. The public properties set by this code are:  N40CLIENT, N40FULL, N35, N30, N20, N11, N10 and N10MEDIA.  These properties will either contain the string "Not Found" or otherwise will contain the service pack level of the relevant .NET framework version.

USAGE

To use in an MSI install, save this code to a file eg NETVER.VBS.

If you want to use it in a LaunchCondition, then sequence in the UI and Execute sequences prior to the LaunchCondition action, as a "Run VBScript from Installation" custom action. This will cover both interactive and silent installs. It is entirely up to you whether you set attribute flags to just run this CA once per process, but there is no issue with it running multiple times, ie both in the UI and Execute sequence.  The public properties can be tested and used as conditions in the install, if required.

Enabling verbose logging for the MSI install will enable checking of these properties to see if their values are correctly recorded and actioned.

As the newer frameworks get updated, it is reasonable to expect that the Microsoft technote will get updated also, but since the way the version information is stored is quite predictable, it is not anticipated that the script will require much, if any, editing until .NET 5 is released.

 


 

Statistics
0 Favorited
0 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
zip file
NETVER.zip   952 B   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Comments

Dec 10, 2012 04:45 AM

i love vbscripts. :-)

Related Entries and Links

No Related Resource entered.