Stop install if specific version is installed

Been searching around and only found a couple examples of something similar.

This is a simple app update that if the currently installed version (typically 3.0.27) is older than the newer version (3.2.8.1), it installs, otherwise the script exits with the “You’re all up to date” message.

This was the latest try, which came from another post on here, I just tweaked it for the app I’m working with.

if($env:PROCESSOR_ARCHITECTURE -eq “AMD64”){$HKLMPath = “HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”}else{$HKLMPath = “HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”}

        $XinkAD = Get-ItemProperty “$HKLMPath*” | Where-Object DisplayName -Like ‘Xink Client AD’

    if($XinkAD.DisplayVersion -eq "3.0.27"){
    (Show-InstallationWelcome -CloseApps 'outlook,emsclient=Xink Client' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt)
    }
    else
    {
    (Show-InstallationPrompt -Message 'You're Xink Client is up to date..' -ButtonRightText 'Exit' -Icon Information)
    }
    Exit-Script -ExitCode 0

The issue is that I can’t get it to just exit with the ‘all good’ msg, and stop the install/script. Not sure how to get it to both show the msg AND exit. Doing it inside the psadt because in order to update the app it and Outlook have to be closed, and i’d rather do it this way than wait/hope the user reboots.

After reading it again, i realized I don’t need to pop up a message stating they are up to date. if I can get it to just exit after it checks the version that’d be great.

So something like this, if worked would be perfect.

if($env:PROCESSOR_ARCHITECTURE -eq “AMD64”){$HKLMPath = “HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”}else{$HKLMPath = “HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”}

    $XinkAD = Get-ItemProperty “$HKLMPath*” | Where-Object DisplayName -Like ‘Xink Client AD’

if($XinkAD.DisplayVersion -lt "3.8.2"){
(Show-InstallationWelcome -CloseApps 'outlook,emsclient=Xink Client' -PersistPrompt)
}
else
{
Exit-Script -ExitCode 0
}

So check version
If less than 3.8.2, start install, otherwise quit quietly.

Tested and it didn’t work, it still ran through the install so i’m missing something.

Why not use the builtin command?

$installed = Get-InstalledApplication -Name 'Xink Client AD'

if ([version]$installed.DisplayVersion -lt [version]$appVersion) {
    Show-InstallationWelcome -CloseApps 'outlook,emsclient=Xink Client' -PersistPrompt
}
else {
    Write-Log -Message "Currently installed version $($installed.DisplayVersion) is already up to date. Skipping installation."
    Exit-Script -ExitCode 0
}

You might want to try a Write-Log in the comparison and run the script from a PS prompt to see if you actually hit the Exit-Script.

1 Like

@Fonta I actually figured it out, but I like the idea of the log, will definitely add give that a try.

This is what I ended up with:

if($env:PROCESSOR_ARCHITECTURE -eq “AMD64”){$HKLMPath = “HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall{B615E380-E157-4A6E-AFA1-7E05EA5FE12B}”}else{$HKLMPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”}
$XinkAD = Get-ItemPropertyValue “$HKLMPath*” -Name DisplayVersion
if($XinkAD -eq “3.2.8”){
Exit 0
}
else {
(Show-InstallationWelcome -CloseApps ‘outlook,emsclient=Xink Client’ -CheckDiskSpace -PersistPrompt)
}

Are you sure that works? It looks like your missing a \ in the AMD64 part, and the part in the else misses the ID.

My code is also a lot cleaner :stuck_out_tongue:

1 Like

It most definitely is. I did do testing on if it read the correct registry entry and it seemed to work but I can always update the code for sure. This was a ‘hack’ job with deadlines and such so if it walked like a duck I figured it was a duck. And it quacked too! lol

I’ll give yours a try!

Ah yeah, I see what you mean. glhf :slight_smile:

Turns out I did it easier just by doing:

## Check file version and proceed, Close Outlook and Xink, and persist the prompt
        $XinkVersion = (get-item 'C:\Program Files (x86)\Xink\Xink Client AD\emsclient.exe').VersionInfo.FileVersion
        
        if($XinkVersion -gt 3.2.8){
            
            Exit 0
        }
        else {


		## Show Welcome Message, close Xink if required, and persist the prompt
		Show-InstallationWelcome -CloseApps 'outlook,emsclient' -PersistPrompt
		}