I have created a setup using Setup project in VS 2010. It install my application into program files folder lets say XXX. My application further creates some files and folder into XXX folder. At the time of uninstall it delete every thing whatever create by setup while files and folder created by my application remains there in XXX.
I wrote some custom code to delete the folder (XXX) using installerclass but does not executes when user uninstall from control panel while executed successfully when uninstall from Setup created by me.

- 1,563
- 4
- 22
- 46
-
3@Davide I know this doesn't answer your question, but you should avoid writing anything in your application installation folder - a user without appropriate permissions may cause your application to fail. (OTOH, I acknowledge that your uninstallation problem would remain even if you write to AddData or similar...) – Branko Dimitrijevic Sep 01 '11 at 11:50
-
Thanks Davide for the advise, I will keep this in mind. – Vipul Dec 11 '12 at 07:17
4 Answers
The first step would be to modify your application so it writes its data in per-user locations instead of the application folder. For example, you can use a custom folder in the current user AppData directory. This way you avoid permission-related problems.
For removing this folder, you can indeed use a custom action. If it's added under Uninstall in your setup project, it should run for both Control Panel and package uninstalls.
Try creating a verbose uninstall log and search for your custom action name to see what happens.

- 21,216
- 5
- 45
- 60
DON'T DO THIS! First, users usually don't appreciate having their data files they put in the application directory deleted without warning (they might only be uninstalling it because they want to move it to a different drive, for example). It's better to leave it up to the end users to manually remove them if they want. Also, if the user happened to install the program in the wrong directory by mistake (for example, C:\WINDOWS) and then went to uninstall it there could be disastrous consequences. Or what if the user hides his precious porn videos inside the application folder? So again, DON'T DO THIS!

- 4,009
- 1
- 26
- 27
I don't think you should write any custom code for that, if all your files are marked as temporary and not permanent, this will be handled directly by the MSI engine.
Play with the configuration and properties of folders, files and the setup project itself and you will get what you need with no code to be written.

- 43,984
- 10
- 98
- 147
-
Can you please help me to get some detailed solution for the above issue? In my case also my application is creating few files at runtime which causes uninstallation process of MSI from control panel to not to remove the folders containing the files. My requirement is on uninstall of MSI all the folders present with the wwwroot folder should be deleted and wwwroot folder must be clean. Can you please help me on this issue? – santosh kumar patro Feb 10 '14 at 09:58
-
I used powershell script to uninstall the msi and in that code now I am calling the following powershell which helps me to delete all the folders within the folder : Remove-Item "C:\Temp\Fldr\*" -Force -Recurse -ErrorAction SilentlyContinue and it resolved the problem. – santosh kumar patro Feb 10 '14 at 11:34
My guess is that your Custom Action for removing files is scheduled in UI section. When uninstall is started from Control Panel, it runs in minimal UI mode, and all your dialogs are skipped.
Your Custom Action must be scheduled in InstallExecute
table.
(To be compatible with UAC, it must be deferred with noimpersonate. Yet your application itself is not compatible with UAC, so it does not really matter.)

- 11,541
- 4
- 39
- 68