Reputation: 2375
We have an Excel AddIn say A written in C#, Add-In Express. The installer is built from setup project in VS. Now we want to integrate it to another bigger add-in application say B. we want to be able to uninstall A during installation of B. B is also written in C#, but its installer is built from Advanced Installer.
I tried VBA like below, AddIns only contain "A XLL Add In" but not "A COM Add In". so it does not work. So I am thinking to write an exe to detect if A is installed and if so, uninstall it.
and call the exe in installer of B.
Anyone know how to "uninstall a program in C#" ? or there is better solutions? thanks
Once I can detect A and uninstall it in an exe, I will be able to hook it in installer of B.
Installer/Uninstaller class in .NET is not an option since I am not using them in installer of B.
Dim item As AddIn
Set item = Application.AddIns("A COM Add In")
If Not item Is Nothing Then
item.Installed = False
'item = Nothing 'Not sure if this does anything
End If
Dim item As AddIn
Set item = Application.AddIns("A XLL Add In")
If Not item Is Nothing Then
item.Installed = False
'item = Nothing 'Not sure if this does anything
End If
Upvotes: 0
Views: 3438
Reputation: 11878
You can uninstall the previous version by invoking MSI directly:
msiexec /x YOUR-PRODUCT-CODE
Replace YOUR-PRODUCT-CODE
with the real product ID used in your MSI package which installed the AddIn A.
You may want to add /qn
option to completely suppress its UI.
MSI also provides API you can use to find out if the product is installed and to uninstall it.
Upvotes: 2
Reputation: 2264
You can use the same Upgrade Code for both installers. If Upgrade Code is the same and installer B has a higher version than A, then A package will be uninstalled by MSI during the installation of B.
Upvotes: 1
Reputation: 3915
You can use WMI - ManagementObject to accomplish this.
ManagementObjectSearcher search = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
ManagementObject product = search.Get().Cast<ManagementObject>().ToList().Where(obj
=> obj["Name"].ToString().StartsWith([Name of product to Uninstall])).FirstOrDefault();
if (uninstallObject != null)
object result = product.InvokeMethod("Uninstall", null);
Upvotes: 0
Reputation: 2880
Your approach is correct - in particular the exe you are creating should be Setup.exe which will ensure that the pre-requisites are met. Ie it will uninstall A.
How you create setup.exe is very dependent on what tools you have to hand though - sorry I can help you much there as I use wix3.0 which is quite limited in this particular regard.
Upvotes: 0