Search code examples
windowsnsis

How to call an nsi function in uninstall section?


I have an nsi script with a function that returns output that I'm trying to call inside the uninstall section. Unfortunately however when I run it I get errors apparently because of the way I call this function. My understanding is that there is a special way to call functions in the uninstall section but i'm not sure how and I was wondering if someone could help me? my code looks like this:

Function TestFunction
   Push $R0
   Rush $R1
   ;do stuff
   Pop $R!
   Exch $R0
FunctionEnd

!macro TestFunction OUTPUT_VALUE
   Call TestFunction
   Pop `${OUTPUT_VALUE}`
!macroend

!define TestFunction'!insertmacro "TestFunction"' 

; Uninstaller

Section "Uninstall"
  ${TestFunction} $R0
  StrCmp $R0 "Test" istest isnottest 

Solution

  • The name of uninstaller functions must be prefixed with un.:

    Function un.DoMagic
    ...
    FunctionEnd
    
    Section "un.Main"
    Call un.DoMagic
    SectionEnd