1

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

Prasad Honrao
  • 192
  • 1
  • 14
  • Have you considered having them separate but feeding into each other so that you run the uninstall script and when that is finished (or closes) it then runs a separate script for the new install – Moiety Design Sep 18 '14 at 21:50
  • I don't understand what you mean that uninstall "starts installing new Addin". Separate lines with "msiexec /x ... /qn" and afterwards "msiexec /i ..." are working fine in a batch normally. But you can have only one MSI process at one time. No parallel installs or uninstalls possible. – Philm Sep 19 '14 at 08:40
  • @Philm Basically I want to uninstall existing excel add-in which was installed using an old MSI and install the new add-in using an updated MSI file. Now when I run the batch file which has both uninstallation and installation commands [2 msiexec commands], it starts uninstallation and immediately kicks-off installation process. There is the main problem. Since only one MSI process can run at a time, I cannot run both the jobs in parallel. Somehow I want to trigger new add-in installation process only when existing add-in is completely uninstalled. I hope I clarified my problem clearly now. – Prasad Honrao Sep 19 '14 at 23:37
  • @MoietyDesign I tried multiple options, however I don't know how I can feed output of first job into second, so that they don't run in parallel. I want something like ContinueWith C# pattern in batch file. Not sure if its even possible. – Prasad Honrao Sep 19 '14 at 23:39
  • Please fill in the exact content of your batch file in your question. Reasoning "blindly" does not lead really further. I still don't understand your problem. If you mean that installing begins before uninstalling has ended, this is not normal. Uninstalling and installing in a batch works for millions of other systems. For safety, I always add a "Call" before every command in a batchfile to assure that it waits for the end. Testing for correct uninstall and waiting in a loop before install starts is a slightly more complicated alternative, but not difficult- is it? – Philm Sep 22 '14 at 13:49
  • @Philm - Below are the batch file contents MsiExec.exe /uninstall Macdata2.AddInSetup(1.0.0.4) MsiExec.exe /package Macdata2.AddInSetup.msi(1.0.0.5) – Prasad Honrao Sep 22 '14 at 15:26

2 Answers2

1

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).

Community
  • 1
  • 1
Philm
  • 2,953
  • 24
  • 23
0

A few things here:

  1. First question is if you are aware of the xlstart folder in Excel which allows you to easily load certain addin files on Excel startup just by putting them into this folder. As far as I know you can't disable addins this way via the Excel GUI, you have to remove them from the xlstart folder to not load them into Excel.

  2. Second issue is that you should update your MSI file to use a major upgrade so that it automatically removes the existing MSI whilst installing the new one. This would probably remove the whole problem that you describe.

  3. Finally you should be able to use start wait msiexec.exe /i /qn File.msi to have your batch file wait for msiexec to return from the first msiexec call. Check Waiting for msiexec.exe to finish. Or you can try MSI Software Deployment Using Batch File.

Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140
  • 1. Nope, I am not aware of xlstart folder and how it will help me to solve the problem described above 2. I am using Add-in express product for my Excel Add-in development as I need to support multiple office versions. As far as know, Add-in express does not provide any way to update an MSI package so that I could uninstall existing add-in and install new one. 3. I will try the option you suggested. As of now my problem has been solved, but its good to know about multiple options. – Prasad Honrao Sep 26 '14 at 23:57
  • The xlstart folder is per-machine, meaning it applies to all users. There is no need for HKCU registry keys to make it work. I don't recall what types of addin files this applied to (what extension they must be). – Stein Åsmul Sep 28 '14 at 18:35