Advertisement
nullzilla

Task - Remove Adobe Reader and Reinstall MUI Version

Mar 3rd, 2020 (edited)
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module $env:SyncroModule -WarningAction SilentlyContinue
  2.  
  3. $InstallIfMissing = $true
  4. $choco = "$env:allusersprofile\chocolatey\choco.exe"
  5.  
  6. function Find-IfInstalled( $program ) {
  7.     $x86 = ((Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall") |
  8.         Where-Object { $_.GetValue( "DisplayName" ) -like "$program" } ).Length -gt 0;
  9.     $x64 = ((Get-ChildItem "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") |
  10.         Where-Object { $_.GetValue( "DisplayName" ) -like "$program" } ).Length -gt 0;
  11.     return $x86 -or $x64;
  12. }
  13.  
  14. # Check current install status
  15. if (Find-IfInstalled ('Adobe Acrobat Reader MUI')) {
  16.     Write-Output "Adobe Acrobat Reader MUI already installed, exiting."
  17.     Close-Rmm-Alert -Category "Task - Remove Adobe Reader and Reinstall MUI Version"
  18.     exit 0
  19. }
  20. if (-not (Find-IfInstalled ('Adobe Acrobat Reader')) -and $InstallIfMissing -eq $false) {
  21.     Write-Output "Adobe Acrobat Reader not installed and InstallIfMissing is set to false, exiting."
  22.     exit 0
  23. }
  24.  
  25. # Sleep if Windows Installer is busy
  26. while ((Get-Process | Where-Object Name -eq 'msiexec' | Group-Object -Property Name -NoElement).Count -gt 1) {
  27.     Write-Output 'Waiting for Windows Installer availability...'
  28.     Start-Sleep 30
  29. }
  30.  
  31. Write-Output "Checking for Adobe Reader process..."
  32. $reader = Get-Process AcroRd32 -ErrorAction SilentlyContinue
  33. if ($reader) {
  34.     # try gracefully first
  35.     Write-Output "Closing Adobe Reader..."
  36.     $reader.CloseMainWindow()
  37.     # kill after five seconds
  38.     Start-Sleep 5
  39.     if (!$reader.HasExited) {
  40.         $reader | Stop-Process -Force
  41.     }
  42. }
  43.  
  44. Write-Output "Removing Adobe Reader..."
  45. Start-Process -FilePath msiexec.exe -ArgumentList "/x {AC76BA86-7AD7-1033-7B44-AC0F074E4100} /qn" -Wait
  46. if (Find-IfInstalled ('Adobe Acrobat Reader MUI')) {
  47.     Write-Output "Adobe Reader uninstall failed"
  48.     Rmm-Alert -Category 'Task - Remove Adobe Reader and Reinstall MUI Version' -Body "Adobe Reader uninstall failed"
  49.     exit 1
  50. }
  51.  
  52. Write-Output "Installing Adobe Reader MUI..."
  53. #Start-Process -FilePath "$choco" -ArgumentList "install adobereader -y -f" -Wait
  54. &$choco install adobereader -y -f --no-progress
  55. if (Find-IfInstalled ('Adobe Acrobat Reader MUI')) {
  56.     Write-Output "Adobe Reader MUI installed"
  57.     Close-Rmm-Alert -Category "Task - Remove Adobe Reader and Reinstall MUI Version"
  58.     exit 0
  59. }
  60. else {
  61.     Write-Output "Adobe Reader MUI not found, install failed"
  62.     Rmm-Alert -Category 'Task - Remove Adobe Reader and Reinstall MUI Version' -Body "Adobe Reader MUI not found, install failed"
  63.     exit 1
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement