With your comments in mind, Gabriel, I did come up with a solution that achieves my goal. I used the DateLastModified property of the file object and stored it in the registry. As you suggested, it is necessary to write the reg keys from a script that is running deferred but that’s not too difficult.
In case it’s useful for others with a similar problem, here’s a summary of what I needed and what I did. I’m sure there are other ways to accomplish this, but this is what worked for me. I’ve attached the three scripts I wrote.
Goal: Install a file and then remove it during uninstall ONLY if it has not changed since installation.
AI Settings and VBscripts:
- Go to the component for the file and check “Do not register this component with Windows Installer” (this prevents the installer from removing the file)
- Create a search ([MYFILE_DATELASTMOD]) that reads the registry value created by script #1; this search will only return a value during uninstall; the value is passed to script #2.
- Create Attached Custom Action: Script #1 gets DateLastModified for the file and writes that value to a registry key in HKCU.
- Execution = "Immediate"
- Condition = (Not Installed)
- Location = Before Finalization/InstallExecute
- Create Attached Custom Action: Script #2 reads the registry entry created by script #1, compares that value to the DateLastModified of the current file and decides whether to remove the file. This script runs deferred with no impersonation only because the file I needed to remove is in a protected directory (C:\Program Files), otherwise this script could be combined with script #3.
- Action Data = [APPDIR];[MYFILE_DATELASTMOD]
- Execution = "Deferred with no impersonation"
- Condition = (REMOVE="ALL")
- Location = Before File Installation/Uninstall
- Create Attached Custom Action: Script #3 removes the registry entry created by script #1. This script is separate from #2 because #2 requires elevation (see comment above) and this one can't run with elevation or it will access the admin user's HKCU and not the one where the reg key was written.
- Action Data = [Manufacturer];[ProductName]
- Execution = "Deferred"
- Condition = (REMOVE="ALL")
- Location = Before File Installation/Uninstall (note: must be placed *after* script #2)
If anyone has recommendations or suggested improvements, please let me know.
Scott
FOLLOW US
Get the latest news in Application Packaging