Uninstalling with INFs


An uninstall mechanism for an INF can be achieved by writing an Install section in your INF that removes the files, registry entries, shortcuts, etc.  Then add your component to the list of programs that can be uninstalled in the Add/Remove Programs application located in Control Panel.

Add/Remove Programs Keys

To add your component to the Add/Remove Programs list, add new keys and values under the following in the registry:

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\app-name","DisplayName",,"description"

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\app-name","UninstallString",,"command-line"

Quiet Uninstall not shown on Add/Remove List:
HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\app-name","QuietDisplayName",,"description"

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\app-name","QuietUninstallString",,"command-line"

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\app-name","RequiresIESysFile",,"4.71"

app-name
This is the name of your application.

description
This is a string that is displayed in the list box in Add/Remove Programs if not QuietDisplayName.

command-line
This is the command line that will be executed when the component is selected from the list box in Add/Remove Programs.  To execute a section in an INF, you can use the Advpack.dll LaunchINFSection (or LaunchINFSectionEx for save/rollback) entry point (described below). In quiet uninstall case, make sure your uninstall command does not pop up UI or reboot prompt.

RequiresIESysFIle
This specifies the least required IE browser version in order to run this component properly. When uninstall the current IE, setup will use this information comparing with the previous IE version to determin if calling your QuietUninstall command or warn user about the potential problem.

Example:
The following AddReg entries will populate the list box in the Add/Remove Programs control panel with a description of "My Test Application" and execute the Remove_TestApp Install section in TEST.INF:

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test","DisplayName",,"MyTest Application"

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test","UninstallString",,"RunDll32.exe advpack.dll, LaunchINFSection test.inf,MySection"

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test","RequiresIESysFile",,"4.71;

HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test","QuietUninstallString",,"RunDll32.exe advpack.dll, LaunchINFSection test.inf,MySection,3"

This example shows that Component 'Test' requires the system having at least IE4.0. User can uninstall it through the Add/Remove list or if user uninstalls the current browser to the IE version earlier then IE4.0, quietly uninstall component 'Test' as well.


Uninstall INF Template

Use this template as a starting point for an INF that registers your application with Add/Remove Programs.  This template works under both Windows 95/98/ME and NT4/2000.

[Version]
Signature=$CHICAGO$

[DefaultInstall]
CopyFiles=InfCopySection
AddReg=GeneralRegKeys,PlatformSpecificRegKeys

[DefaultInstall.NT]
CopyFiles=InfCopySection
AddReg=GeneralRegKeys,PlatformSpecificRegKeys.NT

[DestinationDirs]
InfCopySection=17

[SourceDisksNames]
55="<my-app-description>","",1

[SourceDisksFiles]
<my-inf-filename>=55

[Uninstall]
DelFiles=InfCopySection
DelReg=GeneralRegKeys,PlatformSpecificRegKeys,DelUninstallKey

[Uninstall.NT]
DelFiles=InfCopySection
DelReg=GeneralRegKeys,PlatformSpecificRegKeys.NT,DelUninstallKey

[InfCopySection]
<my-inf-filename>

[DelUninstallKey]
HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<my-app-name>"

[GeneralRegKeys]
HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<my-app-name>","DisplayName",,"<my-app-description>"

[PlatformSpecificRegKeys]
HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<my-app-name>","UninstallString",,"RunDll setupx.dll,InstallHinfSection Uninstall 4 <my-inf-filename>"

[PlatformSpecificRegKeys.NT]
HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<my-app-name>","UninstallString",,"RunDll32 syssetup.dll,SetupInfObjectInstallAction Uninstall.NT 4 <my-inf-filename>"

Description of Parameters

ParameterDescription
<my-inf-filename> The file name of your INF.  Example: "myinf.inf"
<my-app-name>A short name for your application that will used as a registry key name. This string will never be seen by a user.  Make sure that this string is unique to your application, or an Add/Remove programs entry could get spammed.
<my-app-description>A description string for your app that will show up in the Add/Remove Programs dialog and on setup UI.