Archive: NSIS error description

NSIS error description
  I am using NSIS for my application. I want to track the errors which are occurred during the installation of my application and i want it it write to a log(a error log) so that i can know the errors occurred during installation in my customers place. How can i do it in NSIS.. Please reply me soon
Thank u

Use the detailprint command to print debug information to the installation log. Then dump the log to a file in .onInstFailed / .onInstSucces / some other callback function.

I created a macro for realtime logging... I am not sure if the others would call it clean but I tend to love it..


>var NOW

>!macro logme logpath logtext output
${If} ${output} == 's'
SetDetailsPrint both
DetailPrint "${logtext}"
SetDetailsPrint none
${ElseIf} ${output} == 'l'
${time::GetLocalTime} $NOW
::log "${logpath}" "$NOW$\t${logtext}"
${ElseIf} ${output} == 'b'
${time::GetLocalTime} $NOW
nsislog::log "${logpath}" "$NOW$\t${logtext}"
SetDetailsPrint both
DetailPrint "${logtext}"
SetDetailsPrint none

!insertmacro logme ${INSTLOG} "This will log to the log file only" l
!insertmacro logme ${INSTLOG} "This will log to the screen only" s
!insertmacro logme ${INSTLOG} "This will log to both the screen and the log file" l
${INSTLOG} is just my path to the log file so just set that to whatever,

this is a sample output:

11.10.2012 16:06:05    *-----------------------------------------------------*

>11.10.2012 16:06:05 ### Cisco AnyConnect Secure Mobility Client 3.1.00495 Installation Starting
>11.10.2012 16:06:05 ### Build Verison:
>11.10.2012 16:06:05 ### Runtime: 10/11/2012 16:6:5
>11.10.2012 16:06:05 ### Switches: {none}
>11.10.2012 16:06:05 *-----------------------------------------------------*
>11.10.2012 16:06:05 Running Pre-installation Processes ... Please be Patient
11.10.2012 16
:06:05 Attempting to detect chassis type ... Please be Patient
11.10.2012 16:06:05 - Processing detected chassis type: 080041002
11.10.2012 16:06:05 - Processing detected chassis type:
>11.10.2012 16:06:05 - Processing detected chassis type:
>11.10.2012 16:06:23 Pre-installation Processes Complete
11.10.2012 16:06:23 Extracting Files for Installation ... Please be Patient
11.10.2012 16:06:24 Installing Cisco AnyConnect Secure Mobility Client 3.1.00495 Core Components ... Please be Patient
11.10.2012 16:06:25 Installing Cisco AnyConnect Secure Mobility Client 3.1.00495 NAM Components ... Please be Patient
11.10.2012 16:06:26 - Installer Returned Code: 1603
11.10.2012 16:06:26 - Installation Error: 1603
11.10.2012 16:06:30 Cleaning Up Temporary Files ... Please be Patient
11.10.2012 16:06:30 *** Cisco AnyConnect Secure Mobility Client 3.1.00495 Installation Ended in Error ***
>11.10.2012 16:06:30 *-----------------------------------------------------*
>11.10.2012 16:06:30 *-----------------------------------------------------*
>11.10.2012 16:06:30
As you can tell, I use mine when wrapping applications, but an installer would be good just the same... I believe logiclib is all you need if I remember right...

You should use compile-time !if rather than a run-time ${If}. At the moment it is compiling the whole macro on compile when only a single branch of it needs to be compiled.


Can i get any example of using these dumping log to a file in .onInstFailed / .onInstSucces / some other callback function?

You can get info on the callback functions here:
You can find a logdumper example on the 'dump to log file' page I linked. (Pro tip: Read the 'how to use'.)

Thank u all for your replies. Does dumb log to a file( gives only installation log(files copied during install) or errors occurred in installation also?
I want to get error found during installation.

It simply saves whatever is in the installation details window. Like I said, you'll need to use the detailprint command to put extra details / error information in there.

Thank u MSG..Is there any method i can get error description for the error occurred.(For example during re install the some file is kept open in the installed path etc..).Can i get the error description and do error handling for that?

You'll have to do your own error handling. Use ${If} ${Errors} a lot, and add extra commands where necessary to get more info. Also make sure to detailprint return codes if you use external applications / win32 api commands.

Don't i get any error description from NSIS itself? For example a copying file can fail because of so many reasons.So how i can know what exactly the error is?Is there any error description? What about error flag? Does it set to different value for different error?

No, CopyFiles does not give specific error information. Both canceling and errors set the errorflag. If you want more specifics, you'll have to call the appropriate copying command directly through win32 API, using the system plugin.

What about using special builds?What does it do exactly?Can i get errors and its description by using it?

No clue. Try the logging build.

thank u for your replies.I think i can't get error description from NSIS itself. But can i get in which line or where the error has occurred.Using iferrors in every case will make the coding more lengthy and difficult so i want to make it easy.So can i get errors occurred during error with line number or something else?

hey MSG you have also told to use Windows API,using system plugin to track this forum it is mentioned to use System::Call kernel32::WriteFile(...)?e. But can u tell what are the parameters to be passed to Writefile() function?Does kernel32::WriteFile(...)?e will write errors to a file?

No, no it will not. Kichik merely said that appending ?e to a function call through the system plugin will make it put the function's return code on the stack after calling.

thank u MSG..Do you have any example script where system plugin and writefile is used?Because it will help me more to understand it.

Not myself. But if you google for 'nsis system:call writefile' you'll find some examples.

But... Why would you want to use WriteFile? I thought you wanted to copy files?