…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
