• Anthony Stevens

How to Tell If You Have Microsoft .NET Framework 3.5 SP1 installed

Software

…programatically, that is.

It turns out it’s not *quite* the piece of cake that you might imagine.  There’s a good Stack Overflow post that outlines some of the various approaches, and I crafted a little PowerShell script that uses the inspect-the-uninstall-Registry-key solution, but I’m not happy with the approach.  It’s sort of like asking the question “Is there an elephant at the zoo?” and being told the way to find out is to look for a large pile of elephant poop, and deduce that yes, there is an elephant at the zoo.

This approach fails if I willfully (or neglectfully) mess with the source \framework\3.5\ directory, or do any number of other bad things that leaves this particular registry key intact.

Ah well.  Enough caveats.  Here’s the code:

# Is35SP1Installed.ps1
# Checks to see if you have .NET Framework 3.5 SP1
# installed on the machine that this script runs on
$result = $false
gci "hklm:\\software\microsoft\windows\currentversion\uninstall\" -recurse -force |% {
    $key = $_
    $displayName = $key.GetValue("DisplayName")
    if ($displayName -eq "Microsoft .NET Framework 3.5 SP1") {
        Write-Host $displayName
        Write-Host ("Version {0}" -f $_.GetValue("DisplayVersion"))
        $result = $true
    }
}
$result

1 Comment

1 Comment

  1. Justin Dearing  •  Mar 6, 2012 @7:09 am

    You might want to insert a return statement at the bottom of the if statement since you only care about the first match. Also, on my Windows 7 Machine that returns false, and it is fully updated with VS 2008 and 2010. It does have “Microsoft .NET Framework 4 Client Profile” installed. I don’t know how important it is for you to look for Version 4.0 elephant poop in your case, but I figured I’d bring that to your attention.

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>