you may use the If clause to check the installation mode:
You also have to enable the support for reinstallation or repairing the package.
I never used that, but wasnt there a variable like $BeginUninstallScript? I thought there must be a $BeginReinstallScript and $BeginRepairScript?!
no, there is only a $BeginUninstallScript...
And, however, uninstalling means that some commands are just reversed, but this is not possible for all commands. And all executed commands are tried to be reversed. So if you copy files dureing the installation using "CopyFile" they will be removed during the uninstall process and you can't stop this.
Repairing and reinstalling is a kind of common installation with some minor different behavior. AFAIK repair does not reinstall the user part, just the workstation part. MSI files can handle both reinstall and repair so the MsiInstallProduct command will be changed (internally) to MsiReinstallProduct during re-installation. And it will internally use the repair function for repairing the eScript package.
Also the registry keys which are set using the RegLoad command will usually not be re-set during repair, only while re-installing. But there is a option for each value that this one will also be re-set during repair.
So it is not as easy as it might be... ;-) and sometimes you have to play around with all the functions while creating a package. I.e. I have an update for a software which are just some files to be copied in the program folder. Using CopyFile (or InstallFile) causes the files will be deleted (DeleteFile is the reverse command for CopyFile) and in the $BeginUninstallScript part the setup.exe failed because some files are missing... The trick is to not use the InstallFile command, I have to use a script and the xcopy.exe command because there is no reverse command for ExecuteEx / RunAsEx...