1

I’m currently developing a C# project that has a Setup Installer project. During the installation process, is there any way to access the path (especially the name) of the copied MSI file (it gets cached in C:\Windows\Installer) ?

I would like to store this somewhere in a text file in order to be able to uninstall my application directly from within a Form.

TmZn
  • 399
  • 5
  • 16

1 Answers1

1

Uninstall: There is no need to access that file directly, there are plenty of ways to uninstall without using the cached file name: Uninstalling an MSI file from the command line without using msiexec.

The easiest is just to uninstall by product code:

msiexec.exe /x {PRODUCT-CODE-1111-1111-11111111111X}

And you can uninstall by upgrade code (2), or by name:


You are not trying to uninstall the application that is running from its own GUI are you? :-) Breaking the law. Breaking the law. Wouldn't try that.


LocalPath: There are also several ways to retrieve that local cache path via the MSI API:

On Error Resume Next
Set installer = CreateObject("WindowsInstaller.Installer")

' The product name you search for:
search = "Windows SDK EULA"

For Each product In installer.ProductsEx("", "", 7)
   name = product.InstallProperty("ProductName")
   cachepath=product.InstallProperty("LocalPackage")
   If name = search Then
      MsgBox name + ": " + cachepath
      Exit For
   End If
Next

Local Cache Path


Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Thanks for your answer ! The last part did the trick perfectly ! Just a question, why do you say that it would be braking the law to uninstall from within the application itself ? Unfortunately I need to do that as it is requested for a client, even though I find it really dangerous and awkward too ! – TmZn Nov 12 '19 at 16:18
  • 1
    That was just a joke. Then you have to shut down quickly to make that work OK, any open documents that need to be saved? Maybe it is just a viewer? It is very non-standard :-). Wouldn't recommend it, people should uninstall from the Add/Remove applet. I just wrote [an answer showing how to launch that applet](https://stackoverflow.com/a/58822061/129130). – Stein Åsmul Nov 12 '19 at 16:19