Question on registry detection

Topics: Archive - General
Jan 10, 2014 at 4:29 PM
Hi,

I'm was trying to detect .NET Extended via registry GUID if it is installed on machines using the script below and once detected, I would like to ignore or bypass the dotNetFx40_Full_x86_x64.exe installation and continue the install of BrainStorm but if not detected, I would like dotNetFx40_Full_x86_x64.exe to be installed together with BrainStorm. See script below. It kinda works but always installs dotNetFx40_Full_x86_x64.exe regardless of the detection. Thanks for all your help.

*===============================================
  • PRE-INSTALLATION
    If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"
*===============================================
# Show Welcome Message, close applications if required, allow up to 3 deferrals
Show-InstallationWelcome -CloseApps "iexplore,excel,groove,onenote,infopath,onenote,outlook,mspub,powerpnt,winword,winproj,visio" -AllowDefer -DeferTimes 3

Scans for .NET Extended Installation

Get-RegistryKey "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{8E34682C-8118-31F1-BC4C-98CD9675E1C2}" -ContinueOnError

Show Progress Message

Show-InstallationProgress "BrainStorm Quick Help x86 3.02 Installation in Progress..." -WindowLocation "BottomRight" -TopMost $false

Remove any previous versions of BrainStorm

Remove-MSIApplications "BrainStorm"
*===============================================
  • INSTALLATION
    $installPhase = "Installation"
*===============================================
# Install the base EXE
Execute-Process -FilePath "dotNetFx40_Full_x86_x64.exe" -Arguments "/q /norestart"

Install the base MSI and apply a transform

Execute-MSI -Action Install -Path "BrainStormQuickHelpX86.msi" -Transform "Brainstorm_Training_3.0.mst" -Parameters "DESKTOPICON=0 LOGINMETHOD=SSO COMPANYNAME=gm.com /QN"

*===============================================
  • POST-INSTALLATION
    $installPhase = "Post-Installation"
*===============================================

*===============================================
  • Installation Restart Prompt
    $installPhase = "Reboot Required"
*===============================================
#Installation Restart Prompt
Show-InstallationRestartPrompt -Countdownseconds 600 -CountdownNoHideSeconds 60
Coordinator
Jan 10, 2014 at 5:12 PM
.NET detection can be a bit tricky but this should work for you:
    # Get the installed .NET Framework Version
    $dotNetVersions = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version
    ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -ge "4.5") {
            $dotNet45Installed = $true
            Break
        }
    }

    # Install .NET 4.5 if it's not already installed
    If ($dotNet45Installed -eq $false) {
        # Do installation here
    }
    
Hope this helps, Dan
Jan 10, 2014 at 5:41 PM
Edited Jan 10, 2014 at 5:42 PM
Hi,

Thanks for the reply. It somehow worked when .Net extended and client profile is installed on the machine, it will ignore dotNetFx40_Full_x86_x64.exe and continue installing brainstorm but when .net client profile is installed and extended is not installed, the installation fails. See script below. Maybe I'm just missing something. Basically, all machines already has the .net client profile 4.0.303.19 installed but not the .net extended which comes with the full version 4.0.30319.

* PRE-INSTALLATION

If ($deploymentType -ne "uninstall") { $installPhase = "Pre-Installation"

*===============================================

# Show Welcome Message, close applications if required, allow up to 3 deferrals
Show-InstallationWelcome -CloseApps "iexplore,excel,groove,onenote,infopath,onenote,outlook,mspub,powerpnt,winword,winproj,visio" -AllowDefer -DeferTimes 3 
# Scans for .NET Extended Installation
# Get the installed .NET Framework Version
$dotNetVersions = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version
ForEach ($dotNetVersion in $dotNetVersions) {
    If ($dotNetVersion.Version -ge "4.5") {
        $dotNet45Installed = $true
        Break
    }
}

# Install .NET 4.5 if it's not already installed
If ($dotNet45Installed -eq $false) {
    # Do installation here
    Execute-Process -FilePath "dotNetFx40_Full_x86_x64.exe" -Arguments "/q /norestart"
}

# Show Progress Message
Show-InstallationProgress "BrainStorm Quick Help x86 3.02 Installation in Progress..." -WindowLocation "BottomRight" -TopMost $false
# Remove any previous versions of BrainStorm
Remove-MSIApplications "BrainStorm"

*===============================================

* INSTALLATION

$installPhase = "Installation"

*===============================================

# Install the base MSI and apply a transform
Execute-MSI -Action Install -Path "BrainStormQuickHelpX86.msi" -Transform "Brainstorm_Training_3.0.mst" -Parameters "DESKTOPICON=0 LOGINMETHOD=SSO COMPANYNAME=tes.com /QN"
Coordinator
Jan 10, 2014 at 5:48 PM
The following will check for a minimum of .NET 4.0 (not 4.5 as I originally had) and ensure that it's the Full install, not just the Client Profile:
    # Get the installed .NET Framework Version
    $dotNetVersions = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version
    ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -ge "4.0" -and $dotNetVersion.PSChildName -eq "Full") {
            $dotNet4FullInstalled = $true
            Break
        }
    }

    # Install .NET 4.0 (Full) if it's not already installed
    If ($dotNetFullInstalled -eq $false) {
        Execute-Process -FilePath "dotNetFx40_Full_x86_x64.exe" -Arguments "/q /norestart"
    }
Dan
Jan 10, 2014 at 6:55 PM
Hi,

I really appreciate you helping me on this. Hopefully this will be my last one for today. :-) Do I need to copy the script that you gave me to AppDeployToolkitExtensions.ps1 or Deploy-Application.ps1? I copied it to Deploy-Application.ps1 but I'm getting an error. Sorry for being a pain.
Jan 13, 2014 at 2:55 PM
Hi,

Thanks for the reply. I believe, we are getting really close. The activity is now showing on the logs as per the changes that you sent me yesterday to test. The only issue right now is the .Net does not execute after Getting Registry Key and coming back as Key does not exist. The changes that you sent me are shown below and the logs aswell.

Try this:

$dotNetExtendedInstalled = Get-RegistryKey "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{8E34682C-8118-31F1-BC4C-98CD9675E1C2}"

If ($dotNetExtendedInstalled -eq $false) {
# Install the base EXE
Execute-Process -FilePath "dotNetFx40_Full_x86_x64.exe" -Arguments "/q /norestart" }

LOGS

13-01-2014 08:49:39] [Pre-Installation] User selected to continue...
[13-01-2014 08:49:41] [Pre-Installation] Getting Registry key [Registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{8E34682C-8118-31F1-BC4C-98CD9675E1C2}] ...
[13-01-2014 08:49:41] [Pre-Installation] Registry key does not exist: [Registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{8E34682C-8118-31F1-BC4C-98CD9675E1C2}]
[13-01-2014 08:49:41] [Pre-Installation] Spinning up Progress Dialog in a separate thread with message: [BrainStorm Quick Help x86 3.02 Installation in Progress...]
[13-01-2014 08:49:42] [Pre-Installation] Getting information for installed Application Name [BrainStorm]...
[13-01-2014 08:49:42] [Pre-Installation] uninstall string [] does not match "msiexec", so removal will not proceed.
[13-01-2014 08:49:42] [Installation] Executing [msiexec.exe /i "BrainStormQuickHelpX86.msi" TRANSFORMS="Brainstorm_Training_3.0.mst" DESKTOPICON=0 LOGINMETHOD=SSO COMPANYNAME=gm.com /QN /L*v "C:\Windows\Logs\Software\BrainStormQuickHelpX86_Install.log"]...
[13-01-2014 08:49:42] [Installation] Execution failed with code: 1603
[13-01-2014 08:49:42] [Installation] BrainStorm_QuickHelpx86_3.02_EN_01 Installation completed with exit code [1603].
[13-01-2014 08:49:42] [Installation] -------
Jan 13, 2014 at 4:15 PM
Edited Jan 13, 2014 at 4:15 PM
Hi Guys,

I think I'm good now. I did small changes. See below. The only thing is when .net extended is installed, the script will still install the full version which I think is ok as long as it installs the full version once the script detects that .Net Extended is not installed. Thanks so much for creating this tool. Make things so much easier.

Carlos

Get the installed .NET Framework Version

$dotNetExtendedInstalled = Get-RegistryKey "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{8E34682C-8118-31F1-BC4C-98CD9675E1C2}"

If ($dotNetExtendedInstalled -ne $true){

Install .NET Full

Execute-Process -FilePath "dotNetFx40_Full_x86_x64.exe" -Arguments "/q /norestart"
}

LOGS
[13-01-2014 10:09:36] [Pre-Installation] Registry key does not exist: [Registry::\HKEY_LOCAL_MACHINE\SOFTWARE\PSAppDeployToolkit\DeferHistory\BrainStorm_QuickHelpx86_3.02_EN_01]
[13-01-2014 10:09:36] [Pre-Installation] User now has [2] deferrals remaining.
[13-01-2014 10:09:36] [Pre-Installation] Checking for running applications [iexplore,excel,groove,onenote,infopath,onenote,outlook,mspub,powerpnt,winword,winproj,visio]...
[13-01-2014 10:09:36] [Pre-Installation] Applications are not running.
[13-01-2014 10:09:36] [Pre-Installation] Finished checking running applications.
[13-01-2014 10:09:36] [Pre-Installation] User has the option to defer.
[13-01-2014 10:09:37] [Pre-Installation] User selected to continue...
[13-01-2014 10:09:39] [Pre-Installation] Spinning up Progress Dialog in a separate thread with message: [BrainStorm Quick Help x86 3.02 Installation in Progress...]
[13-01-2014 10:09:40] [Pre-Installation] Getting information for installed Application Name [BrainStorm]...
[13-01-2014 10:09:40] [Pre-Installation] uninstall string [] does not match "msiexec", so removal will not proceed.
[13-01-2014 10:09:40] [Pre-Installation] Getting Registry key [Registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{8E34682C-8118-31F1-BC4C-98CD9675E1C2}] ...
[13-01-2014 10:09:41] [Pre-Installation] Registry key does not exist: [Registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{8E34682C-8118-31F1-BC4C-98CD9675E1C2}]
[13-01-2014 10:09:41] [Pre-Installation] Executing [dotNetFx40_Full_x86_x64.exe /q /norestart]...
[13-01-2014 10:11:08] [Pre-Installation] Execution completed successfully with return code 0.
[13-01-2014 10:11:08] [Installation] Executing [msiexec.exe /i "BrainStormQuickHelpX86.msi" TRANSFORMS="Brainstorm_Training_3.0.mst" DESKTOPICON=0 LOGINMETHOD=SSO COMPANYNAME=gm.com /QN /L*v "C:\Windows\Logs\Software\BrainStormQuickHelpX86_Install.log"]...
[13-01-2014 10:11:10] [Installation] Execution completed successfully with return code 0.
[13-01-2014 10:11:10] [Reboot Required] BrainStorm_QuickHelpx86_3.02_EN_01 Installation completed with exit code [0].
[13-01-2014 10:11:10] [Reboot Required] ----------------------------------------------------------------------------------
Marked as answer by ccastillo1005 on 1/13/2014 at 9:21 AM
May 30, 2014 at 1:13 AM
Edited May 30, 2014 at 1:15 AM
I borrowed this to fix an issue I was having and it took a bit of troubleshooting to get working, figured I would share my experience. The below section of code was not actually populating the $dotNet45Installed variable on machines where .NET was not installed, rather the variable would be left blank and the script would skip the install of the per-requisite item because the variable was blank rather than false.
ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -ge "4.5") {
            $dotNet45Installed = $true
To remedy this I changed the greater than to less than, and the value from true to false. I could have completed the if statement with an else to achieve the same results but this was easier and achieves the same result. If the product is not present than it flags as false and installs the pre-requisite, if it is present it leaves the variable blank which skips the install.
ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -lt "4.5") {
            $dotNet45Installed = $false
The complete code looks like this.

    # Get the installed .NET Framework Version
    $dotNetVersions = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version
    ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -lt "4.5") {
            $dotNet45Installed = $false
            Break
        }
    }

    # Install .NET 4.5 if it's not already installed
    If ($dotNet45Installed -eq $false) {
        # Do installation here
    }
sintaxasn wrote:
.NET detection can be a bit tricky but this should work for you:
    # Get the installed .NET Framework Version
    $dotNetVersions = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version
    ForEach ($dotNetVersion in $dotNetVersions) {
        If ($dotNetVersion.Version -ge "4.5") {
            $dotNet45Installed = $true
            Break
        }
    }

    # Install .NET 4.5 if it's not already installed
    If ($dotNet45Installed -eq $false) {
        # Do installation here
    }
    
Hope this helps, Dan