2
votes

For the installation and deployment of my application I'm using Inno-Setup 5.5.4. My current installation structure is the following:

    C:\MyApp
    C:\MyApp\app.exe
    C:\MyApp\FolderA
    C:\MyApp\FolderA\InstalledFile.txt
    C:\MyApp\FolderA\NewFile.txt
    C:\MyApp\FolderB
    C:\MyApp\FolderB\NewFile.txt
    ...
    C:\MyApp\FolderZ

After uninstalling the application, I want to make remove all possible files that could be created by the application except those present in a specific folder. (i.e. the C:\MyApp\FolderA\NewFile.txt).

My first try would be to have one entry for each folder I want to clean in the [UninstallDelete] section. Something like the following:

    [UninstallDelete]
    Type: filesandordirs; Name: C:\MyApp\FolderB
    Type: filesandordirs; Name: C:\MyApp\FolderC
    ...
    Type: filesandordirs; Name: C:\MyApp\FolderZ

However, I don't like this solution since I have to consider to modify the installer each time I add a new folder to the application.

Second approach would be to remove the specific folder only if it is empty and then set application's root folder to be removed. Something like the following:

     [UninstallDelete]
     Type: dirifempty; Name: C:\MyApp\FolderA
     Type: filesandordirs; Name: C:\MyApp\

Would this second approach work? Is there a more reasonable way to achieve this?

2

2 Answers

1
votes

A file can't be deleted when it's accessed by a process. Look for the reason that causes it. Quit all applications and services that are about to be removed before you begin to delete the folders. Be sure there is no other application accessing the files you are about to remove (notepad, word etc). Sometimes it's good to wait a few seconds after ending other processes before removing the files that they have been used (maybe someone else can explain it).

I had once a case where we couldn't find a reason why a file can't be deleted by the uninstaller. After a long while we found out that a running apachemonitor.exe was accessing a log file and we didn't kill that process before. It can be quite difficult to find the blocking process but especially when it's always the same file that can't be deleted you shall better look for the processes you install and use in order to make a proper working unsinstaller.

If you want to delete all files in folder except a special then you should use Pascal-Script in your uninstaller. The function reference (http://www.jrsoftware.org/ishelp/index.php?topic=scriptfunctions) helps a lot here.

You can use FindFirst, FindNext, FindClose to iterate over a directory. Call DelTree(DirName, true, true, true) or DeleteFile for all items you want to remove.

Execute that code inside the CurUninstallStepChanged event if CurUninstallStep=usPostUninstall.

0
votes

Another way how to prevent deleting files on uninstall is use parameter Flags:

uninsneveruninstall; in section [Files]

Info from help:

uninsneveruninstall

Never remove the file. This flag can be useful when installing very common shared files that shouldn't be deleted under any circumstances, such as MFC DLLs.

Note : that if this flag is combined with the sharedfile flag, the file will never be deleted at uninstall time but the reference count will still be properly decremented.