PDA

View Full Version : Force rollback after failed RunProgram



andrelernhart
08-09-2014, 09:23 AM
Hi all,

I run an external My.exe during installation using "Support Files". My.exe returns an error code (0 if successful, any other value if error). The return error is correctly in %_SB_ERRORCODE% (and probably also in %_SB_RETURNEX%).

Well, I check the errorcode - if on error, I want to trigger "Exit Installation" to force a smart rollback.

How to do that? Calling "Exit Installation" does not have any effect, its just ignored.
I stored the My.exe return error code to a variable %_My_EXE_ERROR% (a copy from %_SB_ERRORCODE% when the value is still there and not replaced by a newer value). I put in several places in the script an "if %_My_EXE_ERROR is not 0 then Exit Installation..." block. No effect at all.

How to force to pop up the "Installation failed" dialog and invoke the smart rollback w/o asking the user?

Thanks in advance, André

linder
08-09-2014, 11:04 AM
Hi André,

The "Exit Installation" statement causes the script to terminate completely and returns to the operating system, optionally setting the errorlevel after the program terminates. It does NOT execute any other function (e.g. rollback).

To programmatically invoke smart rollback for updates, you have to stop writing to the uninstall .log ("Set Installer Log Mode" -> Close Installation Log). You can launch the uninstaller (e.g. "Run Command Line...") in "smart rollback" mode. Call the uninstall .exe (point to your uninstall .log) and add the /UR command line switch.

Friedrich

linder
08-09-2014, 11:08 AM
BTW, if you need an example project, just let me know and I'll develop one for you.

Friedrich

andrelernhart
08-09-2014, 12:23 PM
Hi Friedrich,

thanks for fast reply!

I was able to catch the "Run Program" return error code, stop writing to the log, and then invoke uninstall.exe using the "Run Command Line" feature with /UR.
It first asks if everything should be uninstalled... if YES, the whole installation is uninstalled, not just a smart rollback of the failed update... and finally it tells the user that the installation was successful...

This is not the intented behaviour. Thus, I'd really appreciate a sample script.

Requirements:
1) Assume a successful initial installation (e.g. an application.exe, some DB files, some .chm files)
2) Run an update script which patches some of the previously installed files (such as .chm or the application.exe). During update, for some reasons a "Run Program" operation returns an error code.
3) This error is catched and should invoke a smart rollback only of the already applied changes during this failed update - the previously successful installation should remain intact.
The user should be informed that this failed update was not successful: either by means of a
a) custom dialog (which content I can assemble knowing the offending details) or
b) with a generic predefined dialog, just saying that the operation failed - (the particular failures I can show when they occur)

Thanks ahead for your time, highly appreciated.
best regards, André

linder
08-09-2014, 01:17 PM
Hi André,

We are doing this on a regular basis. The "update" has to use the same uninstall .exe / .log file. The /UR command line switch rolls-back all the logged items from the update install. Even the SetupBuilder install image uses this feature that lets you rollback to previous builds.

BTW, if it displays messages then you forgot to run the uninstall in silent mode. And of course, you have to log the command in the uninstall. Otherwise, it can't be rolled back. If you are using a custom uninstall, it also has to handle the "smart rollback" scenario.

I'll develop a simple demo project for you, no problem.

Friedrich

andrelernhart
08-10-2014, 07:02 AM
Friedrich,

I tried another couple of hours... no success so far. It seems that I miss some important "detail", it still uninstalls the whole installation, not only the failed update.

A small sample would be very helpful, thanks in advance!

regards
André

linder
08-10-2014, 08:19 AM
André,

I have uploaded a simple demo:

http://www.lindersoft.com/projects/SmartRollback.zip

Unzip the archive into a test folder. Then compile and run "InitialSetup.sb8". This will install two files: FILEA.TXT (contents is Version 1) and FILEB.TXT (contents is Version 1). Then compile and run "UpdateSetup.sb8". This will update FILEA.TXT to Version 2. But after that, it will execute the rollback feature and rollback Version 2 to Version 1. When you see the "Rollback" message box you can check the contents of FILEA.TXT -- it will tell you that it is Version 2., After the rollback it says again Version 1.

Does this help?

Friedrich

andrelernhart
08-10-2014, 11:13 AM
Friedrich,

thank you very very much for this demo!
Based on your demo (seeing that it works), I finally found the bug in my script. As always a stupid glitch I repeat frequently during the last 40 years or so: the variable pointing to the location for uninst.exe/uninst.log was not correctly initialized. I debugged and used a lot of messageBoxes until I found the bug.

Smart Rollback works now like a charm, excellent!

What I don't understand in your UpdateSetup.SB8 (line #34): you check for previous version using the PRODUCTGUID. Running the script a second time, the return value is 0, indicating "not found" (what you show in the MessageBox). Why the entry for this PRODUCTGUID in Registry is gone? A glitch in Smart Rollback or do I miss some basic understanding?

Thanks again, best regards André

linder
08-10-2014, 11:41 AM
André,

Unfortunately, my demo really was too quick-n-dirty <g>. Sorry !!!

Please re-dowonload:

http://www.lindersoft.com/projects/SmartRollback.zip

See Lines 39+40 in the "UpdateSetup.sb8" project:

! Backup Add/Remove Panel data
Set Installer Flag $SB_BACKUPADDREMOVEPANEL$ to "1"

This will backup the required registry items for updates.

Does this help?

Friedrich

andrelernhart
08-10-2014, 11:54 AM
Friedrich,

yes, this helps me to save this Sunday :-)

Perfect, thank you very much, highly appreciated!

Best regards André

linder
08-10-2014, 11:59 AM
You are very welcome, André :)

Friedrich