I launch msiexec in another process and wait for exit:
var p = new Process
{
StartInfo =
{
FileName = \"msiexec\",
Arguments = string
First, the other remarks concerning 1638 return code are a bit misleading. When you install the exact MSI file a second time, you get a return code 0 like you already (and correctly) observed. That's "correct" behaviour or in other words: That's how MSI is designed. Moreover there are no changes made to your existing setup in this case. If you delete all files before the second install, you end up with nothing although MSI is returning zero. So return code alone is not helping you for this scenario.
In short terms, you have the following possibilities:
Easy but seems unnormal: Just uninstall (maybe silently) the product before you install with:
msiexec /x {yourproductcode} /qn
(You will not get an error even if the product has been NOT installed before because of the silent parameter "/qn"
Advised if enough for you: Just use the repair mode if you want to install a second time: Example:
msiexec /i ... REINSTALL=ALL REINSTALLMODE=vemus
Optimal: Use a launcher (boot-strapper or other names are the same thing) to test IF the product is already installed, etc. With this you can automate the previous options (pre-uninstall or add of repair parameters). This can be done also with scripts but in each case this is programming, so not the easiest way.
4.
Now we come to the mentioned 1638 return code in some other answers: IF (and only if) your build system (like InstallShield does by default) changes the socalled MSI PackageCode) in every build AND you are trying to update this slightly different built (MSI) to a previous installed one, you get the 1638 return code.
These things are often misunderstood. Changing the PackageCode for every build is a very recommended practice. On the other hand it will complicate things for you not only a bit, if you will release such MSIs to your customers. The name of this update type is "small update or minor upgrade" (their difference is not important here, because it has the same limitations for you. If you really want to solve your problem with a return code, you can use this. But as said, the 1638 you will not get for the second install of the exactly SAME MSI !
To continue the recommendation about updates, there are more ways: the easiest to handle way (for beginners) are Major Upgrades. This is what is called "new version" in another answer which was not wrong, but not so exact. For Major Upgrades you have to change MSI PackageCode and MSI ProductCode at minimum, recommended is changing the ProductVersion also. (Another way would be to use MSI patches as delta updates, but this is not easy either).