2
votes

One quick question about inno-setup: Can I customize which files to be removed by uninstaller? As I know, the uninstaller always uninstall all the files created by installer. If the answer is Yes, what should I do for that?

My case is: After I install my application, directory "{pf}\myapp\" include some dlls, two executable files, and there created two desktop icons and uninstallers for each executable file. What I expect is user can uninstall each executable file, rather than all the files; and if it's the only executable file left, uninstaller will remove all the files.

Thanks in advance.

1
Please make the question that you are asking more clearCody Guldner
Sorry for poor English, I have detailed the question;Webber
You mention an uninstaller for each executable. Can you confirm that this is TWO seperate packages being installed into the same location? If so, you just need the sharedfile flag on the shared files (in both setups), causing Inno to only remove them once they're finsihed with.Deanna
Thanks a lot for help. Actually, the two executable files are installed in one package. And I want to remove only one of executable file and according desktop icon when the uninstaller in same group selected, and remove all the files if it's the last executable file.Webber
I'm still confused. Inno doesn't have any concept of a part uninstall. Yes it can skip some files during an uninstall but then they are left forever. If you need them to be individually uninstallable, they need to be two seperate install packages. (These can be wrapped in a 3rd setup to look like a single package though)Deanna

1 Answers

2
votes

If you want separate uninstallers, you have to write separate installers. The general rule is you have to write a separate installer per application.

This said, you can have any number of shared files, which can be dll's, executables, etc. that are shared between distinct applications.

Windows have well defined procedures to keep track of shared files, with a reference count. The reference count is incremented by the installer and decremented by the uninstaller. The files are removed from the system only if the reference count reach 0 during uninstallation.

You use the sharedfile flag to instruct the installer the file is shared. The MyLib.dll file is shared in the following example:

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "MyLib.dll"; DestDir: "{sys}"; Flags: sharedfile
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme

From the documentation (emphasis mine):

sharedfile

Specifies that the file is shared among multiple applications, and should only be removed at uninstall time if no other applications are using it. Most files installed to the Windows System directory should use this flag, including .OCX, .BPL, and .DPL files.

Windows' standard shared file reference-counting mechanism (located in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs) is used to keep track of how many applications depend on the file. Each time the file is installed, the reference count for the file is incremented. (This happens regardless of whether the installer actually replaces the file on disk.) When an application using the file is uninstalled, the reference count is decremented. If the count reaches zero, the file is deleted (with the user's confirmation, unless the uninsnosharedfileprompt flag is also specified).