@echo off REM uninstallstring.bat REM REM Written By: Jim Cameron REM Created: 2009-12-29 REM Last Modified: 2009-12-30 REM Version: 1.0 REM REM Usage: REM REM uninstallstring REM uninstallstring program REM REM Purpose: If no arguments are given to the batch file on the command line, REM it will display a list of all the programs with UninstallString values, REM i.e., all the registry keys under REM HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall. If REM an argument appears on the command line, it should be one of the values REM reported when no arguments are given to the script, i.e. a program name, REM such as "vim" or "Adobe Flash Player ActiveX" (don't actually put the quotes REM around the names, even if there are spaces in the name. E.g. for the latter REM case you would use the following: REM REM uninstallstring Adobe Flash Player Activex REM REM When a program name is included on the command line, uninstallstring.bat REM will determine the "UninstallString" value in the registry for that REM particular program, i.e. the location for the uninstall program for a REM particular piece of software. It will return just that value. E.g., for REM the "uninstallstring vim", it would return the following: REM REM C:\Program Files\vim\vim72\uninstall.exe REM REM If it can not find an uninstall registry value for the program listed it REM will return the following: REM REM ERROR: The system was unable to find the specified registry key or value. REM The following example shows a "reg query" command that could be issued from REM the command line to determine the value of "UninstallString" for the Vim REM editor software. The last line of output contains the "value name", REM "value type", and "value data", which is the part of the output of interest. REM C:\>reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Vim /v UninstallString REM REM HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Vim REM UninstallString REG_SZ C:\Program Files\vim\vim72\uninstall.exe REM First, display the UninstallString values present in the registry. REM Values returned by the reg query command will be in the following format: REM REM HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Vim IF "%1"=="" ( GOTO Show_All ) ELSE ( GOTO Find_String ) :Show_ALL set _All=reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall FOR /f "tokens=6* delims=\" %%A IN ('%_All%') Do echo %%B GOTO End :Find_String REM Set _Program to be the parameter entered on the command line. REM Use %* rather than %1 to cover cases where the program has spaces in the REM name. set _Program=%* REM Set the variable _UninstallString_Query to the reg query command to be issued. set _UninstallString_Query=reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%_Program%" /v UninstallString REM There are two parts at the beginning of the line, the "value name" and the REM "value type" that aren't relevant, By specifying "2*" the "value name" is REM ignored, the "value type" goes into %%A and %%B holds everything else on REM the line. FOR /f "skip=2 tokens=2*" %%A IN ('%_UninstallString_Query%') Do echo %%B :End