MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
December
Sun Mon Tue Wed Thu Fri Sat
   
30    
2009
Months
Dec


Wed, Dec 30, 2009 10:48 pm

Determining the Uninstall Location for a Program

I needed to be able to determine the uninstall program for a program that was installed on a system by querying the registry. When you go to the Control Panel and choose "Add or Remove Programs" or "Uninstall a Program", you see a list of installed programs, such as is shown below:

Uninstall a program (Windows 7)

The information listed there is associated with Uninstall registry keys that are found at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall in the Windows registry.

Uninstall a program (Windows 7)

I created a batch file to query the registry to show all of the programs that have such an Uninstall key and that will accept a program name and return the uninstall command found under that key for the program.

The first example below shows the output when no arguments are passed to the batch file on the command line. For the second example, the script finds the uninstall value in the registry for the program vim. The third example shows the output when the value is not found. The fourth example shows how to query when the name of the program has spaces in it.
C:\Users\JDoe\Downloads>uninstallstring
AddressBook
Adobe Flash Player ActiveX
All ATI Software
ATI Display Driver
CDisplay_is1
Connection Manager
DirectDrawEx
DXM_Runtime
Fontcore
IE40
IE4Data
IE5BAKEX
IEData
MobileOptionPack
MPlayer2
PuTTY_is1
RealPopup_is1
SchedulingAgent
SecondLife
Total Uninstall 5_is1
Vim
WIC
{9D07059A-EC99-4F03-9BF2-BE40FB007822}
{FB08F381-6533-4108-B7DD-039E11FBC27E}
C:\Users\JDoe\Downloads>uninstallstring vim
C:\Program Files\vim\vim72\uninstall.exe
C:\Users\JDoe\Downloads>uninstallstring gvim
ERROR: The system was unable to find the specified registry key or value.
C:\Users\JDoe\Downloads>uninstallstring Adobe Flash Player ActiveX
C:\Windows\system32\Macromed\Flash\uninstall_activeX.exe

The batch file is as follows:

@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

Download uninstallstring.bat

References:

  1. Creating DOS Batch Files
    Useful Information: tons of info stuffed into a small site
  2. For /f - Looop through text
    SS64.com Command line reference
  3. For - Looop through command output
    SS64.com Command line reference
  4. Batch files - How To ... Verify if Variables are Defined
    Rob van der Woude's Scripting Pages
  5. Microsoft Windows XP - If
    Microsoft Corporation
  6. Microsoft DOS if command
    Computer Hope's free computer help
  7. Information on batch files
    Computer Hope's free computer help
  8. Microsoft Registry Tools
    Softpanorama (slightly skeptical) Open Source Software Educational Society
  9. Quotes, Escape Chars, Delimiters
    SS64.com Command line reference
  10. Tips for using the Windows command prompt in Windows XP
    The Command Line in Windows
  11. Batch File Command Reference
    At The Data Center - by Don WIlwol
  12. Batch file count tokens in var
    Computing.net Computer Tech Support Forum

[/os/windows/commands] permanent link

Wed, Dec 30, 2009 5:07 pm

Handle Installation with WPKG

I wanted to install Mark Russinovich's Handle (version 3.42) program using WPKG. I created the following package file for its installation.
<?xml version="1.0" encoding="UTF-8"?>

<packages>

<package
  id="Sysinternals"
  name="Sysinternals"
  revision="1"
  reboot="false"
  priority="1">
  
  <check type="file" condition="exists" path="%PROGRAMFILES%\Utilities\Sysinternals\handle.exe" />
  <!-- Test first to see if the Sysinternals directory already exists. 
  Otherwise, if it exists and an attempt is made to create it, which
  will fail, the entire installation process will fail as well. 
  Note: the double quotes must appear around the file name used as
  a test for "if not exist", since %PROGRAMFILES% expands to a directory
  path with a space in it. -->
  <install cmd='cmd /c if not exist "%PROGRAMFILES%\Utilities\Sysinternals" mkdir %PROGRAMFILES%\Utilities\Sysinternals' />
  <install cmd='cmd /c copy %SOFTWARE%\Utilities\Sysinternals\handle.exe "%PROGRAMFILES%\Utilities\sysinternals\."' />
  <remove cmd='cmd /c rmdir /s /q "%PROGRAMFILES%\Utilities\Sysinternals"' />
  <upgrade cmd='' />

</package>

</packages>

When handle.exe is first run, it prompts for the acceptance of the End User License Agreement (EULA). You can avoid the prompt by running the command with the /accepteula parameter, e.g. handle /accepteula. It has to be run from from any account under which you want to use the program. It creates the registry key HKEY_USERS\SID\Software\Sysinternals\Handle, where SID is the Security Identifier for the user under which it is being run. Within the key, it creates the value below:

NameTypeData
EulaAcceptedREG_DWORD0x00000001 (1)

You can just use handle /accepteula or you can use REG ADD HKCU\Software\Sysinternals\Handle /v EulaAccepted /t REG_DWORD /d 1 /f under the relevant account to create the registry key.

References:

  1. Handle
    By: Mark Russinovich
    Published: November 19, 2008
    Windows Sysinternals
  2. Microsoft Windows XP - Cmd
    Microsoft Corporation
  3. Batch File Commands
    Windows Support Center
    James A. Eshelman, Proprietor & Webmaster
  4. The option "-accepteula" doesn't work Title is required
    MIR-ROR
  5. >>> EULA prompt when running PSTools <<<
    Date: December 19, 2006
    Sysinternals Forums
  6. handle.exe
    Date: October 16, 2007
    Sysinternals Forums

[/os/windows/software/wpkg] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo