2

When I run an installer that allows a custom install location/path, the files will be correctly placed at the location that I select.

When I run the same MSI and select remove (or uninstall from add/remove programs), how does it know the install location so the correct files are removed?

I thought it would be stored at 'Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{GUID}', but when I look at that location for my installed software, the 'InstallLocation' key is empty.

However, no matter how I uninstall it, it knows which folder to go remove, no matter where I put it. Is that information stored elsewhere in the registry, or in the MSI file itself?

Joe Tilley
  • 21
  • 3

2 Answers2

3

This is a very complicated question as MSI can be configured to drop its uninstall files anywhere you tell it. Usually by default though it will create an uninstall .msi file with a specific name in C:\Windows\Installer.

But don't depend on the uninstall .msi being placed in this directory and don't rely on there being an uninstall path in the Uninstall registry key. This key is as much about convenience for the end-user as anything else.

The uninstall information is usually contained within the MSI file, but it need not be and during installation it can create keys to aid upgrading and uninstallation. The information that an installation will leave in the registry is entirely down to how you configure the .msi database.

Adding a few more things... many installers like Nullsoft, InstallAware and InstallShield like to do their own stuff and put their uninstall information in other places. So InstallShield likes to create an InstallShield Installation Information folder and Nullsoft likes to create .dat files and an uninstall.exe. But beyond all this, these installers are still invoking MSI and creating installation tables and database. So where the uninstall information is actually located it not an exact science!

The Welder
  • 725
  • 5
  • 21
  • This is related to an uninstall feature in our software manager, so luckily that's the only case we need to consider. It relies on the default behavior of Windows, which is exactly what you describe: a randomly named .msi file is dropped into C:\Windows\Installer. But I'm still not sure how I can run the same .msl that I used to install, and it knows how to uninstall from the custom path I select. Does msiexec modify my original MSI, or place the install location somewhere else in the registry by default? I'm just trying to mimic the "uninstall from add/remove programs" functionality. – Joe Tilley Feb 11 '20 at 17:03
  • We are using WiX to generate our MSIs, and we're not doing anything exotic to store uninstall information in a custom location. My question is really just asking about the Windows default behavior, not any custom or exotic behavior. Maybe the answer is that there is no "default" behavior, even for WiX. – Joe Tilley Feb 11 '20 at 17:30
2

UPDATE:

Find Component's Installation Location: Is there way to detect install location without uninstall registry nor C:\Windows\Installer?


Implementation Details: How MSI stores these things are implementation details that should not be meddled with, attempted modified or used directly for any purpose - just so that is clear. You should go through the MSI API which is implemented as Win32 functions with complementary COM wrappers for access via scripting languages.

Registry: The MSI database is stored mostly in the registry, but there also components on disk - some of which you refer to - for example %SystemDrive%\Windows\Installer (a super-hidden folder that should not be modified in any way). The MSI database is stored in numerous locations throughout the registry:

  • HKCR\Installer
  • HKCU\Software\Microsoft\Installer
  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer
  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Installer
  • Etc...

Some of these are real, some are aliases, some are merges. It is all a bit fuzzy. Again: implementation details - a well-known euphemism for all of us to: "give up right now, will you"? :-). Just apply the MSI API to acquire the information you need.


MSI API: A lot of stuff to read above to get to the point, go via the MSI API to get your information on directory resolution. What we have to do is a bit exotic, we have to spin up a session object for the installed product and run two standard actions (built-in MSI actions from Microsoft) in order to resolve the directory table and installation directories of the MSI in question (about "costing"). Below is a practical sample:

For the record:

Set installer = CreateObject("WindowsInstaller.Installer")

' Other test product codes: {2F73A7B2-E50E-39A6-9ABC-EF89E4C62E36}

productcode = Trim(InputBox("Please paste or type in the product code you want to look up details for:", _
              "Find Product Details (test GUID provided):", "{766AD270-A684-43D6-AF9A-74165C9B5796}"))
If search = vbCancel Or Trim(productcode) = "" Then
   WScript.Quit(0)
End If

Set session = installer.OpenProduct(productcode)

' Crucially, resolve the directory table and properties by running "MSI Costing"
session.DoAction("CostInitialize")
session.DoAction("CostFinalize")

' Can be any directory property from the Directory table in the MSI:
MsgBox session.Property("INSTALLFOLDER")

' Open the MSI in Orca to find the directory folder property names

Throwing in a link to an old answer on how to list tables inside an MSI file.


Resolve All: Got a bit carried away and made one more update to resolve ALL directories for any installed package. Here is a script (not tested much):

' https://stackoverflow.com/questions/17543132/how-can-i-resolve-msi-paths-in-vbscript
' On Error resume Next

Set installer = CreateObject("WindowsInstaller.Installer")

' Other test product codes: {2F73A7B2-E50E-39A6-9ABC-EF89E4C62E36}

const READONLY = 0
Dim DirList

productcode = Trim(InputBox("Please paste or type in the product code you want to look up details for:", _
              "Find Product Details (test GUID provided):", "{766AD270-A684-43D6-AF9A-74165C9B5796}"))
If search = vbCancel Or Trim(productcode) = "" Then
   WScript.Quit(0)
End If

Set session = installer.OpenProduct(productcode)
session.DoAction("CostInitialize")
session.DoAction("CostFinalize")

set view = session.Database.OpenView("SELECT * FROM Directory")
view.Execute
set record = view.Fetch

Do until record is Nothing
    
    ResolvedDir = session.Property(record.StringData(1))
    DirList = DirList + record.StringData(1) + " => " + ResolvedDir + vbCrLf
    set record = view.Fetch

Loop

' Dismiss dialog with ESC key if it falls off screen 
WScript.Echo DirList ' Use WScript.Echo due to MsgBox restrictions (number of characters)

Links:

Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140