2

Can someone help me to build a custom action in MSI which will copy itself after successful installation to some X location. I have already seen it can be done using .exe but I want to do it only with CA.DLL (C#) as this exe will be an overhead.

Lazy Jack
  • 123
  • 10
  • 1
    possible duplicate of [Can a .msi file install itself (presumably via a Custom Action)?](http://stackoverflow.com/questions/88078/can-a-msi-file-install-itself-presumably-via-a-custom-action) – Wim Coenen Jul 13 '12 at 18:06

1 Answers1

2

Here's an example VB script that will find an installed product by name and copy the cached copy of the MSI. This will work on Windows 7 and later, as the full MSI is cached and any embedded cab files remain in the MSI. You just get the MSI without the payload on older systems.

Dim installer, products, product, productCode
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")

For Each productCode In installer.Products
  If InStr(1, LCase(installer.ProductInfo(productCode, "ProductName")), LCase("My Product Name")) Then Exit For
Next

If IsEmpty(productCode) Then Wscript.Quit 2

Set products = installer.ProductsEx(productCode, "", 7)
filesys.copyFile products(0).InstallProperty("LocalPackage"), "c:\path\to\newcopy.msi"
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
saschabeaumont
  • 22,080
  • 4
  • 63
  • 85