Dutch Gemini's Weblog Pages

May 3, 2011

InnoSetup and the missing Uninstall Icon on Windows 7

Filed under: Programming,Setup — dutchgemini @ 4:53 pm
Tags: , , ,

I am creating an installation package with InnoSetup for an Excel Add-In and have added an uninstall icon. This works fine except on Windows 7. In the Programs and Features section, all I got was a generic application icon, like the one shown below (related to ISTool from Bjørnar Henden):

Within the ISS script I have indeed set the uninstall icon to a customised icon based on Excel’s own:

UninstallDisplayIcon=ExcelWithBigA.ico

which looks like:

Rather amused with the issue but determined not to accept this ‘quirk’, I reviewed the script and found a way for setting the uninstall icon the way I wanted.

Just a brief intro to the uninstall icon. From Inno Setup’s help we learn that

[Setup]: UninstallDisplayIcon
Description:

This lets you specify a particular icon file (either an executable or an .ico file) to display for the Uninstall entry in the Add/Remove Programs Control Panel applet on Windows 2000 and later. The filename will normally begin with a directory constant.

If the file you specify contains multiple icons, you may append the suffix “,n” to specify an icon index, where n is the zero-based numeric index.

If this directive is not specified or is blank, Windows will select an icon itself, which may not be the one you prefer.

Examples:
UninstallDisplayIcon={app}\MyProg.exe
UninstallDisplayIcon={app}\MyProg.exe,1

By reading the explanation more in depth —something programmers usually don’t do— I discovered that the icon (or the file containing the icon) had to be available on the target PC, otherwise Windows cannot locate it. Obviously my setup package didn’t install this file, hence the missing icon, but above all I also did not want really to install this small file either. Point is that, except for Windows 7, all other OS’s did show the icon.

So I tried to find a way to circumvent the problem and came with the solution while I was working on the AppId directive. In the explanation for this directive, the unistall section in the Registry was mentioned, reason enough for me to take a quick look into it. There, I discovered that Inno Setup had posted the name of the unistall icon under a REG_SZ value named ‘DisplayIcon‘ which contained 'ExcelWithBigA.ico‘.

Now, my application is uninstallable, and the unistaller comes packed with the same icon file I wanted to use (specified in the SetupIconFile directive). After changing ‘DisplayIcon‘ to the name of the uninstaller (copied from the REG_SZ value ‘UninstallString‘), Windows 7 magically displayed my customised icon. Without bringing the custom icon in the installation package.

The nice thing in Inno Setup is that the name of the uninstaller is available as a constant called {uninstallexe} and you can use it while developing your installation script. Setting the uninstall icon in the ISS script to:

UninstallDisplayIcon={uninstallexe}

does the job the way I want.

Dutch.

P.S.: you can also use Registry command to assign icons at run-time. I’ve seen that this should be performed at the very last stage during setup, best is during CurStepChanged(ssDone), since Inno Setup may void your value if performed too sone while writing its own data to the Registry somwhere in the middle of the installation:

; Preprocessor stuff - define an AppId (this is just a sample)
;
#define TheAppId "{AABBCCDD-1122-3344-5566-778899AABBCC}"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
;
AppId={{#TheAppId}

[Code]

// {...other code...}

procedure CurStepChanged(CurStep: TSetupStep);
    begin
        case CurStep of
        ssInstall:
            // Do_Pre_Install();
        ssPostInstall:
            // Do_Post_Install();
        ssDone:
            // Update the Registry with the Uninstall icon from the unistaller.
            //
            RegWriteStringValue(HKEY_LOCAL_MACHINE,
            'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#TheAppId}_is1',
            'DisplayIcon',
            ExpandConstant('{uninstallexe}'));
    end;
end;
Advertisements

3 Comments »

  1. Nice, i had the same problem, but since you didn’t provide a proper inno setup example, this knowledge is useless

    Comment by Frank — January 30, 2012 @ 11:03 am | Reply

    • It’s in the text. This single line is enough (provided you use the SetupIconFile directive also):

      UninstallDisplayIcon={uninstallexe}

      Drop it somewhere in the [Setup] section.

      Comment by dutchgemini — January 30, 2012 @ 11:32 am | Reply

  2. thank you buddy…you did great job..this is common problem with many setup creating program..

    Comment by Nilanga — June 21, 2012 @ 9:37 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: