Search code examples
c#installshieldinstallscript

Custom Message on Failure of Custom Action Installshield


I have a custom action that runs at the time of installation which is an exe written in C#. This exe grants permission to a User to a specific folder, if this task fails there is no use for the installation to continue. I need it to rollback, but only after displaying appropriate error message.

Now what I have tried is the following

  1. Edited the exe to update an entry in registry to denote if its execution was successful/failure.
  2. Added a second custom action to read the registry and display an error message. This is an install script.

My need

To rollback the installation on reading a failure entry from registry.

The script that I have written

function CheckRegistry(hMSI)    
STRING keyValue;
NUMBER nType, nSize;        

begin

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
if (RegDBGetKeyValueEx ("CSVExtraction", "AccessGranted", nType, keyValue,nSize) < 0) then
    MessageBox ("RegDBGetKeyValueEx failed.", SEVERE);
    abort;
else
    if(keyValue != "true") then
        MessageBox("Granting access to the Installation Folder failed; Hence exiting installation",SEVERE);
        abort;
    endif
endif

end;


Solution

  • There is no way to do what you ask. You could show a message from your EXE before returning a non-zero exit code, but then Windows Installer would still show the Error 1722 message.

    If you can instead run a function from a DLL, you have more options. Instead of returning errors, you'd be able to set properties (assuming this is an immediate mode action), and could use those properties to do further things, such as show another dialog, or exit the installation without the Error 1722 message.

    Credit: Old answer to similar problem