Search code examples
c#exceldeploymentwindows-installerscriptcs

Automate deployment of Excel AddIn


I have created an Excel Add-in using AddIn Express .Net component. Business users install the add-in using the MSI provided by the build team. Everytime we make any changes to the product and provide it to business users, they need to manually uninstall existing Add-in and then install new one with the updated MSI.

I wanted to know if there is any way this process can be automated using some windows batch file, scriptcs or a small C# console program. Ideally, it should uninstall existing Add-in, wait for uninstallion process to complete and then install new AddIn.

I tried multiple options using Msiexec, scriptcs etc, but without any success so far. My main problem is once the existing add-in uninstallion process starts, it immediately starts installing new Addin, which then pops up standard windows message that 'Installation is already in progress...'

Any help would be appreciated.

Thanks


Solution

  • I answered already a similiar question where it seemed to help:

    Windows batch file does not wait for commands to complete

    Normally, when you have a batch file with two lines:

    call msiexec /x {...} /qb
    call msiexec /i "c:\myPath\myProduct.msi" /qb
    

    it should work in the sense that the uninstall waits before install starts.

    • The "call" is important !
    • For uninstalls of previous versions you have to use /x {ProductCode to fill in} instead of /x "filename" . In each case using the product code is safer.
    • To be sure what happens, you can add a pause line between the two and at the end.

    If it still seems not to work you have to loop until the product is really uninstalled, wait two seconds and proceed then with an install.

    There are several possibilities to find out, if a program is still installed.

    Most people would recommend a VB script as the easiest solution, at least these are most known. Here is a VBS snippet from saschabeaumont for an uninstall call from another question: MSI Install Fails because "Another version of this product is already installed"

    It mainly finds out the ProductCode of a given productname (part), and starts uninstall, if it fits (be careful about partial matches). You can use it for the same thing and additionally copy the algorithm a second time to ask asynchronously, if the uninstall has already been finished (= product is no longer in list of installed products).

    Of course it is possible in other script languages, namely JScript, Powershell and traditional programming languages. It is difficult to do in pure batch scripts- for example you could test the ProductCode registry entry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, if a product is installed. But only one disadvantage to mention: You have to consider the difference, if batch is started from 32/64 bit subsystem and/or MSI is 32/64 bit. Therefore I would advise instead using VBS instead of a batch (you can call it from the batch with cscript xxx.vbs).