Archive: Silent install with error level


Silent install with error level
I'm trying to create a silent installer, which returns an errorlevel if there where any errors during the installation.

I've found some useful information in the manual and forums here, but I still have some questions.

I found that I can use "SetSilent" to prevent my script from asking for some user interaction. So if the installer is not able to overwrite a file, e.g. if the process is sill running, does this mean the file is skipped and the installer continues with the next file? And in this case, is there any error level set?
And if so, can I get this error level with "GetErrorLevel"? But how do I return this value when the script is finished?

I hope anyone can help.


copied from NSIS manual,

The File command sets the error flag if overwrite mode is set to 'try' and the file could not be overwritten, or if the overwrite mode is set to 'on' and the file could not be overwritten and the user selects ignore.
Something like this should do the trick,
.....
FileOpen $0 '$TEMP\setup.log' w
ClearErrors
File 'somefile.ext'
IfErrors 0 +2
FileWrite $0 'somefile.ext failed$\r$\n'
File 'someother.ext'
IfErrors 0 +2
FileWrite $0 'someother.ext failed$\r$\n'
.......
FileClose $0
.......
ClearErrors
FileOpen $0 '$TEMP\setup.log' r
loop:
FileRead $0 '$1'
IfErrors done
MessageBox MB_OK '$1'
goto loop
done:
FileClose $0
.....

Thanks for your reply.

I've tried this... but I still get no return value from my installer.

My installer code looks like this:


SetOverwrite try
SetAutoClose true
SetSilent silent

ClearErrors

File /r "folder\*.*"
IfErrors 0 +2
SetErrorLevel 17 ; set to something other than -1 0 1 2

GetErrorLevel $0

IfErrors 0 +2
MessageBox MB_OK '$0'



So if a file can not be overwritten (SetOverWrite try), i would expect to have the error level set to 17 and after the process displayed in my messagebox.
I have an executable in my install dir running when starting the installer, so it cannot be written to. But I don't get any response from my installer.

If I do not set the error level, I get a -1 (error level never set) displayed in my messagebox.

What is wrong?

Hmmmm... I've tried to echo the error level as described here , and it works.

But I still wonder why this error level isn't displayed in my messagebox.


        SetOverwrite try
SetAutoClose true
SetSilent silent

ClearErrors

File /r "folder\*.*"
IfErrors 0 +2
SetErrorLevel 17 ; set to something other than -1 0 1 2

GetErrorLevel $0

StrCmp $0 "-1" +2
MessageBox MB_OK '$0'

@RegShoe

File /r "File /r "folder\*.*"
IfErrors 0 +2
SetErrorLevel 17 ; set to something other than -1 0 1 2

GetErrorLevel $0

IfErrors 0 +2
MessageBox MB_OK '$0'"
You are using IfErrors twice to check a single error. That doesn't work because IfErrors resets the error flag. RedWine's code will work because he is checking data that is set (or not set) depending on the error condition.

Don