do not delete install directory after uninstall
This commit is contained in:
+9
-20
@@ -1,6 +1,6 @@
|
||||
## $APP_NAME must be set by the calling script or specified here
|
||||
# $APP_NAME must be set by the calling script or specified here
|
||||
|
||||
## Get all of the uninstall registry keys
|
||||
# Get all of the uninstall registry keys
|
||||
$UNINSTALL_KEYS = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
|
||||
$UNINSTALL_KEYS += Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
|
||||
|
||||
@@ -12,10 +12,10 @@ Function Get-GUIDFromMSIUninstallString {
|
||||
}
|
||||
|
||||
Foreach ( $reg in $UNINSTALL_KEYS ) {
|
||||
## Get the uninstall key
|
||||
# Get the uninstall key
|
||||
$REG_PROPERTY = Get-ItemProperty -Path $reg.PSPath
|
||||
|
||||
## Get the display name of the app
|
||||
# Get the display name of the app
|
||||
$DISPLAY_NAME = $REG_PROPERTY.DisplayName
|
||||
|
||||
# Get the UninstallString
|
||||
@@ -24,33 +24,22 @@ Foreach ( $reg in $UNINSTALL_KEYS ) {
|
||||
# Get the ModifyPath
|
||||
$MODIFYPATH = $REG_PROPERTY.ModifyPath
|
||||
|
||||
## Make sure the DisplayName matches what we're looking for
|
||||
# Make sure the DisplayName matches what we're looking for
|
||||
If ( $DISPLAY_NAME -ilike $APP_NAME ) {
|
||||
## Make sure the software was installed using an MSI
|
||||
# Make sure the software was installed using an MSI
|
||||
If ( $REG_PROPERTY.WindowsInstaller -eq 1 ) {
|
||||
## Get the install location
|
||||
If ( $REG_PROPERTY.InstallLocation ) { $INSTALL_LOCATION = $REG_PROPERTY.InstallLocation }
|
||||
|
||||
## Get the product code from the UninstallString
|
||||
# Get the product code from the UninstallString
|
||||
If ( $UNINSTALLSTRING ) { $PRODUCT_CODE = $(Get-GUIDFromMSIUninstallString -str $UNINSTALLSTRING) }
|
||||
|
||||
## Get the product code from the ModifyPath
|
||||
# Get the product code from the ModifyPath
|
||||
ElseIf ( $MODIFYPATH ) { $PRODUCT_CODE = $(Get-GUIDFromMSIUninstallString -str $MODIFYPATH) }
|
||||
|
||||
## Uninstall the app
|
||||
# Uninstall the app
|
||||
If ( $PRODUCT_CODE ) {
|
||||
LogMsg "Uninstalling ${DISPLAY_NAME} ${PRODUCT_CODE}"
|
||||
$arguments = '/X{' + $PRODUCT_CODE + '} /qn /norestart'
|
||||
Try { Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
|
||||
If ( $INSTALL_LOCATION ) {
|
||||
If ( Test-Path $INSTALL_LOCATION ) {
|
||||
LogMsg "Deleting install directory"
|
||||
Try { Remove-Item $INSTALL_LOCATION -Recurse -Force }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Else {
|
||||
|
||||
Reference in New Issue
Block a user