Archive: error at install time


error at install time
Alright, I have a running installer.
It is supposed to write some settings to a file. After installation the file exists but is empty (zero length).

Now I'd like to know what went wrong. The error flag is set, but why? Is there some way to get an error number or message for further information (not just for the user, it's also me...)?


You can use NSIS MessageBoxes to check file handle in write command is the same as was returned by file open command. File must have write permission. GetLastError() is available using System plug-in.


I thought to have opened the file with write access, and the handle should be the same. The hint to GetLastError is what I am after, but somehow I cannot find a header file containing GetLastError. Do I understand I have to define that myself? This is my first such attempt....

My code looks like this:

CreateDirectory "$INSTDIR\etc"
CopyFiles $LICFILE $INSTDIR\etc
ClearErrors
FileOpen §0 $INSTDIR\etc\config.properties w
IfErrors showerror
FileWrite $0 "home=$INSTDIR"
FileWrite $0 "license=$LICFILE"
FileWrite $0 "projects=$INSTDIR\Projects"
ifErrors showerror
FileClose $0
ifErrors showerror
Goto continue
showerror:
MessageBox MB_OK "ERROR: "

continue:


My MSDN says GetLastError is in the kernel32.dll


FileOpen §0 "$INSTDIR\etc\config.properties" w
...
FileWrite $0 "home=$INSTDIR$\n"
System::Call 'kernel32.dll::GetLastError() i .r0'

should return error code to $0. Use it after write command. Use quotas if NSIS var or expression may have blank spaces (or this is implemented in NSIS already? :) ).

Thank you for that sample. Reading the System plugin documentation I found out that I was wrongly using registers as temporary variables. Your hint checking the file handle told me I have to declare my own variable. Now that one works.

Will try your suggestion to still show errors when they occur. Thank you very much.