Quantcast
Channel: psappdeploytoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1769

New Post: If statement to check for an installed application then uninstall if found.

$
0
0
This is what I have done for Jave and Adobe in the past. Java Example below. Because you are uninstalling an application that was installed via MSI, this should work with your application:
Show-InstallationProgress "Removing old Versions of Java..."
Get-Process -Name "jusched.exe"  -EA SilentlyContinue | Stop-Process -Force -EA SilentlyContinue
$Java7Apps = Get-WmiObject -query "select * from win32_Product where name like `"Java 7 %`""
If ($Java7Apps -is [System.Array]) {
    foreach ($Java in $Java7Apps) {$Java.Uninstall()}
}
elseIf ($Java7Apps) {$Java7Apps.Uninstall()}
The above code first finds the jusched.exe process. If it is running it kills it. This is a java process that can effect the install of the new version. I include this because your app could have something similar.

Then it searches WMI for any application that is installed with a name that starts with "Java 7 ". It assigns those object(s) (applications) to a variable.

The IF then checks if it is an array. If it is, then there are more than 1 version of this application installed. In the case of Java, it could be 32 and 64 bit. It then loops through all of the items in the array and uninstalls them. If it is not an array, the ELSEIF will check if the variable exists. If it does, then it removes the single version of java in the variable. If not, the install continues without uninstalling.

So, what you would need to test with your application is the following
Get-WmiObject -query "select * from win32_Product where name like `"App Name %`""
When you get a result of your application only, you should be able to insert that into the script.

This would go into the PRE-INSTALLATION section of the Deploy-Application.ps1 script.

Hope this helps.

Viewing all articles
Browse latest Browse all 1769

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>