Archive: How to include REPAIR,REMOVE featture in NSIS?


How to include REPAIR,REMOVE featture in NSIS?
I have written nsis script for my application.The installation steps are working fine.If i install second time in same directory it should ask REPAIR or REMOVE option? How do i include this feature in my script?


Can anyone help me?

Thanks.


You'll have to code this yourself. You'll have to write autodetection code, show a custom (nsDialogs) page if necessary, and execute different installation code inside your sections depending on the option chosen by the user.


Thanks MSG.
ok..using nsDialogs customize the installation page.but when i install same application second time,then only include repair or remove option.How can i find out the application already installed or not?


WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
I saw this code in my script by default when i created installer.Is this lines are related to repair or remove feature?


In your custom page function, add some code that does some auto-detection of your application:
${If} ${FileExists} "$INSTDIR\Somefile1.ext"
${AndIf} ${FileExists} "$INSTDIR\Somefile2.ext"
;Show a custom page
${EndIf}

Also: In the custom page's leave function, set a $variable to remember what option the user chose, and in your sections, simply do
${If} $variable == "repair"
;do repair stuff
${Else}
;do reinstall stuff
${EndIf}


The easiest solution is to create nsDialogs page with 2 radiobuttons: Repair and Remove.

Repair will simply launch installer as is - so all files, values, settings etc will be overwritten to their default values.

Remove will launch uninstaller (and immediately quit installer)


Thanks Slappy. I have tried.
Function nsDialogsPage

nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateRadioButton} 0 0 100% 12u "Repair"
Pop $hwnd
${NSD_OnClick $hwnd ???
${NSD_CreateRadioButton} 0 13u 100% -13u "Remove"
Pop $hwnd
${NSD_OnClick $hwnd ???
nsDialogs::Show
FunctionEnd

How to call un installer function? I think un installer function starts from this funtion un.init. If i put un.init it should returns error message? How to call un installer function?


Originally posted by ilaiyaraja
How to call un installer function?
You cannot call an uninstaller function, but you can execute the uninstaller:
ExecWait "$INSTDIR\Uninstall.exe"

Thanks MSG.
It's working fine using this command.


You cannot call an uninstaller function, but you can execute the uninstaller:
ExecWait "$INSTDIR\Uninstall.exe"
Function Remove
ExecWait "$INSTDIR\Uninstall.exe"
FunctionEnd.
It will call the un insall function and open the un intall window.once the user click the un install button then only the files are removed.
Is there any way if the user click remove radio button immediately un install functionality happen without opening one more window or dont want to ask again user input?

Well you could just copy all the uninstall code (delete files, registry, etc) from the uninstall section to a RemovePrevious section in your installer. Or create a silent uninstaller I guess, but that's probably overkill.

(Keep in mind that it's bad form to be making changes to a user's system before the user clicks Install. Any page before INSTFILES should not be writing/deleting stuff. Therefore it's best to put the delete code in a section, because sections are executed only on the instfiles page. Maybe it could be the first section of your installer, and maybe an always-enabled one.)


Well you could just copy all the uninstall code (delete files, registry, etc) from the uninstall section to a RemovePrevious section in your installer. Or create a silent uninstaller I guess, but that's probably overkill.

(Keep in mind that it's bad form to be making changes to a user's system before the user clicks Install. Any page before INSTFILES should not be writing/deleting stuff. Therefore it's best to put the delete code in a section, because sections are executed only on the instfiles page. Maybe it could be the first section of your installer, and maybe an always-enabled one.)
ok..thanks. MSG "it's bad form to be making changes to a user's system before the user clicks Install".
Based on this i have changed the scenario.

If the user checked the remove radio button,then un install the software like the status bar and followed by finish page and finally end.Is it possible?
Function Remove
ExecWait "$INSTDIR\Uninstall.exe"
Quit
FunctionEnd.
This is my remove function code.

Well you could make an uninstaller with only an uninstfiles page, sure. But then you're still making changes to the system before your own installer's instfiles page. My point is it's better to call that uninstaller from your first section, not from a page's leave function or something like that.