Search code examples
windowsinstallationservicemacrosnsis

retrieve variable value from nsh file nsis


I am creating installer using nsis. I have created .nsh file using SIMPLE SC to start, stop and remove services. I have used macros for this.

When I call this in nsi file it works. But I would like to know the return value for start service (SimpleSC::StartService "${SVC}" "${Args}" "${Timeout}", Pop $0). how do I retrieve the $0 value of nsh file in my nsis file


Solution

  • If you have some helper macros that return a result, you can leave the result on the stack:

    !macro DoSomething
    Push $0
    Push $1
    
    Push "Pretend that this is a function that does something and puts the result on the stack"
    Pop $0 ; Result we want to return
    
    Pop $1
    Exch $0
    !macroend
    
    !insertmacro DoSomething
    Pop $0
    MessageBox MB_OK $0
    

    or store it in a register as part of the macro:

    !macro DoSomething outvar
    Push $0
    Push $1
    
    Push "Pretend that this is a function that does something and puts the result on the stack"
    Pop $0 ; Result we want to return
    
    Pop $1
    Exch $0
    Pop ${outvar}
    !macroend
    
    !insertmacro DoSomething $0
    MessageBox MB_OK $0