Search code examples
nsisuninstallationuninstallstring

NSIS uninstaller doesn't run un.onInit


In my .nsi file I have the following logic in the un.onInit function:

Function un.onInit

  MessageBox MB_YESNO "This will uninstall. Continue?" IDYES checkRunning
  checkRunning:
    FindProcDLL::FindProc "app.exe"
    IntCmp $R0 1 0 notRunning
    MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "${PRODUCT} is running, please close it so the installation can proceed." /SD IDCANCEL IDRETRY checkRunning
    Abort

  notRunning:
    !insertmacro Init "uninstaller"
FunctionEnd

However, the messageBox (and the process is running message) is never shown. So I went through a lot of documentation and apparently running silent mode prevents this method being called so I added SilentInstall normal and SilentUnInstall normal to the .nsi file. However, this doesn't work either.

I tried invoking the uninstaller by manually going to the uninstall.exe and by running the installer which checks if there is already a version installed and if there is calling:

uninst:
    ClearErrors
    ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
    ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"
    StrCmp $R0 "" done
    Abort

Yet both of these invokes do not trigger to 'normal' mode. So how can I get my un.onInit function to be called?

Edit:

As someone asked for the whole file, here it is. I copied the relevant parts only, but if more is needed feel free to check it out. Note that the whole file is already quite old, I am merely updating it.


Solution

  • After upgrading the MUI2 (Modern User Interface 2.0), downgrading to NSIS 2.5 and using the NsProcess plug-in, I got it working. The function is now being called and my check works using the new plugin. The FindProcDLL plugin is broken on NSIS > 2.46