inno-setuppascalscript

Uninstallation order


Can I find somewhere actual order, in which events and sections are executed during uninstall? For example, will UninstallDelete occur earlier than usPostUninstall uninstall step?

Inno Setup has "Installation order" article in manual, but it looks more like compilation order, not execution.


Solution

  • The uninstallation order is an opposite of the installation order, just as the manual says (and it is really the installation order, not a compilation order).

    It's simply because there's no programmed uninstallation order. The installer records its steps into uninstall log and the uninstaller just processes the log in an opposite order, without any option to alter the order.

    The event functions fit in the uninstallation process as follows (only major uninstallation steps shown):


    I've tested this on a simple installer:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    DefaultGroupName=My Program
    UninstallDisplayIcon={app}\MyProg.exe
    OutputDir=.
    
    [Files]
    Source: "MyProg.exe"; DestDir: "{app}"
    
    [Icons]
    Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
    
    [UninstallRun]
    FileName: "{app}\MyProg.exe"
    
    [UninstallDelete]
    Type: files; Name: "{app}\test.dat"
    
    [Code]
    
    function InitializeUninstall(): Boolean;
    begin
      Log('InitializeUninstall');
      Result := True;
    end;
    
    procedure InitializeUninstallProgressForm;
    begin
      Log('InitializeUninstallProgressForm');
    end;
    
    procedure DeinitializeUninstall;
    begin
      Log('DeinitializeUninstall');
    end;
    
    procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
    begin
      Log('CurUninstallStepChanged + ' + IntToStr(Integer(CurUninstallStep)));
    end;
    

    The uninstaller log is like (it does not show all the steps):

    2025-01-27 11:25:44.024   Log opened. (Time zone: UTC+01:00)
    2025-01-27 11:25:44.024   Setup version: Inno Setup version 6.4.0
    2025-01-27 11:25:44.024   Original Uninstall EXE: C:\Program Files (x86)\My Program\unins000.exe
    2025-01-27 11:25:44.024   Uninstall DAT: C:\Program Files (x86)\My Program\unins000.dat
    2025-01-27 11:25:44.024   Uninstall command line: /SECONDPHASE="C:\Program Files (x86)\My Program\unins000.exe" /FIRSTPHASEWND=$180B1A /INITPROCWND=$221010 /log="C:\test\uninstall.log" 
    2025-01-27 11:25:44.024   Windows version: 10.0.26100
    2025-01-27 11:25:44.024   Windows architecture: x64 (64-bit)
    2025-01-27 11:25:44.025   Machine types supported by system: x86 x64
    2025-01-27 11:25:44.025   User privileges: Administrative
    2025-01-27 11:25:44.025   Administrative install mode: Yes
    2025-01-27 11:25:44.025   Install mode root key: HKEY_LOCAL_MACHINE
    2025-01-27 11:25:44.027   Created protected temporary directory: C:\Users\marti\AppData\Local\Temp\is-QNLH0.tmp
    2025-01-27 11:25:44.028   InitializeUninstall
    2025-01-27 11:25:44.028   Message box (Yes/No):
                              Are you sure you want to completely remove My Program and all of its components?
    2025-01-27 11:25:44.833   User chose Yes.
    2025-01-27 11:25:44.833   CurUninstallStepChanged + 0
    2025-01-27 11:25:44.949   InitializeUninstallProgressForm
    2025-01-27 11:25:45.011   CurUninstallStepChanged + 1
    2025-01-27 11:25:45.011   Starting the uninstallation process.
    2025-01-27 11:25:45.014   Running Exec filename: C:\Program Files (x86)\My Program\MyProg.exe
    2025-01-27 11:25:46.466   Process exit code: 0
    2025-01-27 11:25:46.470   Deleting registry key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\My Program_is1
    2025-01-27 11:25:46.509   Deleting file: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\My Program\My Program.lnk
    2025-01-27 11:25:46.511   Deleting directory: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\My Program
    2025-01-27 11:25:46.513   Deleting file: C:\Program Files (x86)\My Program\MyProg.exe
    2025-01-27 11:25:46.513   Deleting directory: C:\Program Files (x86)\My Program
    2025-01-27 11:25:46.513   Failed to delete directory (145). Will retry later.
    2025-01-27 11:25:46.513   Deleting file: C:\Program Files (x86)\My Program\test.dat
    2025-01-27 11:25:46.514   Deleting Uninstall data files.
    2025-01-27 11:25:47.044   Deleting directory: C:\Program Files (x86)\My Program
    2025-01-27 11:25:47.048   Uninstallation process succeeded.
    2025-01-27 11:25:47.048   Removed all? Yes
    2025-01-27 11:25:47.048   Need to restart Windows? No
    2025-01-27 11:25:47.059   CurUninstallStepChanged + 2
    2025-01-27 11:25:47.059   Message box (OK):
                              My Program was successfully removed from your computer.
    2025-01-27 11:25:47.657   User chose OK.
    2025-01-27 11:25:47.657   CurUninstallStepChanged + 3
    2025-01-27 11:25:47.657   DeinitializeUninstall
    2025-01-27 11:25:47.659   Log closed.