3 Replies Latest reply on Sep 27, 2018 2:17 PM by Jeff Geller

    Pharos uninstall script

    Scott Kiser Wayfarer

      I created these scripts for SCCM in my enterprise, to enable automatic removal of Pharos printers and the Pharos Popup client from client PCs, without removing Pharos Remote if it is installed.

       

      YMMV - feedback welcome.

       

      Here's the detect script, needed for the SCCM application:

      if (!( test-path "C:\Program Files (x86)\Pharos\bin\pop*" )) { write "Installed" }

       

      And the uninstall script:

      #Pharos uninstall script for Powershell v0.5 by Scott Kiser

      #last updated 2018-05-15

      $pathbin = "${env:programfiles(x86)}\Pharos\bin"

      # don't run if this is a Pharos server

      if ((!( test-path "$pathbin\Pserver.exe" )) -and (!( test-path "$pathbin\DBserver.exe" )) -and (!( test-path "$pathbin\PopupSrv.exe" ))) {

      # detect stuff we wish to avoid removing

      if ( test-path "$pathbin\AdminLauncher.exe" ) { $admin = "1" }

      if ( test-path "$pathbin\PharosSystems.LoggingService.exe" ) { $logging = "1" }

      if ( test-path "$pathbin\PharosSystems.Remote.dll" ) { $remote = "1" }

      if ( test-path "$pathbin\Reports.exe" ) { $reports = "1" }

       

      # find all Pharos printers

      $printers = ( get-printer | where { $_.PortName -like "PharosPopupPort" } )

       

      # compile a unique list of driver names

      $drivernames = ( get-printer | where { $_.PortName -like "PharosPopupPort" } ).drivername | get-unique

       

      #remove printers

      foreach ( $printer in $printers ) { remove-printer -name $printer.name }

      #remove drivers

      foreach ( $drivername in $drivernames ) { remove-printerdriver -name $drivername }

       

      #stop the Pharos 'task master' service

      $servicename = "Pharos Systems ComTaskMaster"

      stop-service $servicename

       

      #copy the file if it's not there for some reason

      # this was in the legacy code, I can't imagine why it was needed

      $path = "${env:programfiles(x86)}\PharosSystems\Core"

      $filename = "ctskmstr.exe"

      $sourcedir = "\\ivytech\sccm\SoftwareRepository\Pharos\uninstall-silent"

      If(!(test-path $path)) { New-Item -ItemType Directory -Force -Path $path }

      If(!(test-path "$path\$filename")) { copy-item "$sourcedir\$filename" $path }

       

       

      # unregister and wait

      start-process -filepath "$path\$filename" -argumentlist "-unregserver" -nonewwindow -wait

       

       

      # kill the popup network process if it's running

      # this was not in the legacy code, I found it was needed if one recently printed

      $popnet = Get-Process popnet -ErrorAction SilentlyContinue

      if ($popnet) {

        # try gracefully first

        $popnet.CloseMainWindow()

        # kill after five seconds

        Sleep 5

        if (!$popnet.HasExited) {

          $popnet | Stop-Process -Force

        }

      }

       

      # remove files

      if ((!( $admin )) -and (!( $logging )) -and (!( $remote )) -and (!( $reports ))) {

      remove-item -path "${env:programfiles(x86)}\Pharos" -recurse

      remove-item -path "${env:programfiles(x86)}\PharosSystems" -recurse

      } else {

      remove-item -path "${env:programfiles(x86)}\Pharos\bin\pop*"

      }

       

      #remove registry keys

      if ((!( $admin )) -and (!( $logging )) -and (!( $remote )) -and (!( $reports ))) {

      remove-item -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos' -recurse -force

      remove-item -path 'HKLM:\SOFTWARE\Wow6432Node\PharosSystems' -recurse -force

      } else {

      remove-itemproperty -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos\Installed Components' -name 'Pharos Notify' -force

      remove-itemproperty -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos\Installed Components' -name 'Pharos Popups' -force

      remove-item -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos\Installed Modules' -recurse -force

      remove-item -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos\Installed Packages' -recurse -force

      remove-item -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos\Notify' -recurse -force

      remove-item -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos\Popup Client' -recurse -force

      remove-item -path 'HKLM:\SOFTWARE\Wow6432Node\Pharos\Popup Monitor' -recurse -force

      }

      #remove uninstaller

      if(!(test-path "${env:programfiles(x86)}\Pharos")) { remove-item -path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Pharos' -recurse -force }

      # remove pharos printer port

      remove-item -path 'HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Pharos Systems Popup Port Monitor' -recurse -force

       

       

      #bounce spooler

      stop-service spooler

      start-service spooler

      }