Archive: behavior when File command encounters an error


behavior when File command encounters an error
Is there a way to suppress the dialog box that NSIS presents if there's an error in a File command (the one that says "error opening file for writing...")?

Clearly running in silent mode suppresses the dialog box but I'm looking for something less drastic than that.

The reason I'd like to suppress the dialog box is that if the user chooses Cancel (when AllowSkipFiles is off) or Abort (when AllowSkipFiles is on), I don't get control back in my script. The installer just exits. I'm trying to find some way to learn that File errors happened in my script.

I suppose another alternative would be to tell NSIS that I don't want to allow the user to cancel in case of File errors. Then it's my responsibility to handle them in the script.

Thanks for your help.

-DB


This macro will attempt to replace the file. If the file is locked, will replace it on reboot. I don't have a locked file at the moment so I haven't tested it.

!include "FileFunc.nsh"
!include "LogicLib.nsh"

!define FileTry `!insertmacro _FileTry`
!macro _FileTry _FilePath
ClearErrors
SetOverwrite try
File `${_FilePath}`
${If} ${Errors}
Push $0
Push $1
GetTempFileName $0
File /oname=$0 `${_FilePath}`
${GetFileName} `${_FilePath}` $1
Rename /REBOOTOK `$0` `$OUTDIR\$1`
Pop $1
Pop $0
SetRebootFlag true
${EndIf}
SetOverwrite lastused
!macroend

OutFile FileTryDemo.exe

Section Main
InitPluginsDir
SetOutPath $PLUGINSDIR
${FileTry} `LockedFile.exe`
SectionEnd

Thanks for the code. It appears the most important part for me is:

SetOverwrite try

That seems to turn off the dialog box in case of file extraction errors. On reading the docs again it seems more obvious but I definitely needed a pointer.