Batch script Search for string in registry key ,if found perform uninstallation

Last week,I was working on Intergraph application upgrade to latest version.Client has different versions of Intergraph and the removal of older versions is not straight forward like other applications using msiexec /x{ProductID} /qn.

The command line is different for all these versions and I cannot put these command lines in one script and run on remote computers using Configmgr. Doing by so,will give error on the higher version of clients while running uninstallation for older applications.For ex: client is having Version 2011 R2 and when the script runs ,it will have 2011 R1 uninstallation command line ,this will give error saying ,you cannot perform this on newer version installed computer.

This process leads me to write simple batch script to check if the specific application name (what I supposed to remove) found in registry then perform the uninstall actions for each version ,if not found simply do nothing.

This batch script is to search for specific application display name ,if found,do some custom actions like uninstallation or what needed.

@echo off
REM Title : Search application name from registry

REM Scanning registry key (HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node) for any old applications and remove
REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /F  "Application Name1" /S
REM Application name1 can be anything ,like display name or product ID etc.
IF %ERRORLEVEL% EQU 0 (
REM write your custom query here
)

REM Scanning registry key (HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node) for any old applications and remove
REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /F  "Application Name2" /S
REM Application name2 can be anything ,like display name or product ID etc.
IF %ERRORLEVEL% EQU 0 (
REM write your custom query here
)

 

3 Responses to "Batch script Search for string in registry key ,if found perform uninstallation"

  1. It would be more useful for us if you provide the exact script which you have used in your scenario.
    And one doubt if we need to uninstall the previous versions lets assume 10, then we need to write 10 times of the above same pseudo Coden for un install 10 previous version of same application.

    Reply
    1. yes,if you go with this type of batch file and not use msiexec /x uninstallation method. Normally for msi removals,you can just go with msiexec /x method for all .IF the product code found ,it will remove else it will ignore but in my case,its completly different uninstall method .Below is command what i used to remove the intergraph .
      REM Scanning registry key (HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node) for any old applications and remove

      REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /F "Intergraph SmartPlant Markup" /S
      IF %ERRORLEVEL% EQU 0 (
      REM Uninstall HF#4 for 2011 R1
      "\\sccmserver\application name\setup.exe" -s /f1"\\sccmservername\application name\Uninstall_SPM2011.iss" /f2"C:\windows\temp\uninstall_SPM.log"
      )
      so the above cmd line will try to remove using the recorded file (.iss) .

      Reply

Leave a Reply