Tuesday, May 24, 2011

Assorted Ways to Detect .NET 4.0

CMD / BAT

@echo off
reg query hklm\software\microsoft\.NETFramework\v4.0.30319 >nul
if %errorlevel%==0 (
echo found
) else (
echo not found
)

VBScript Registry Test

Set oShell = CreateObject("Wscript.Shell")
On Error Resume Next
bKey = oShell.RegRead("HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\")
If err.Number = 0 Then
wscript.echo "found"
Else
wscript.echo "not found"
End If

PowerShell Registry Test

if (test-path hklm:\software\microsoft\.NETFramework\v4.0.30319) {
write found
} else {
write not found
}

VBScript Folder Test

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
If objFSO.FolderExists(“C:\Windows\Microsoft.NET\Framework\v4.0.30319”) Then
wscript.echo “found”
Else
wscript.echo “not found”
End If

PowerShell Folder Test

If (test-path $env:windir"\Microsoft.NET\Framework\v4.0.30319") {
write found
} else {
write not found
}

VBScript WMI Win32_Product Test

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Product WHERE Caption LIKE '%.NET Framework 4%'",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Next
Post a Comment