PDA

View Full Version : How to remove files and folders created by application during uninstall



Ivan_mysammy
09-27-2010, 08:12 PM
Hi,

I have searched through the threads in this community, but still didn't find what I want. I guess there should be a very simple method to remove the files not created by the installer during uninstall, cuz this is a very common senario. Can anyone give me some idea?

Thanks,

Rouslan
09-28-2010, 07:21 AM
1) You can use RemoveFile table if you know name of file to delete.
(See msi help or MSDN)
2) Also you can use custom action.

Ivan_mysammy
09-28-2010, 11:30 AM
1) You can use RemoveFile table if you know name of file to delete.
(See msi help or MSDN)
2) Also you can use custom action.

Thanks for your reply, Rouslan.
It looks like installscript custom action works for my senario. I will try these two method and post my results later

Ivan_mysammy
09-28-2010, 11:45 AM
1) You can use RemoveFile table if you know name of file to delete.
(See msi help or MSDN)
2) Also you can use custom action.

Rouslan, for the first method, how to set "Component" field in RemoveFile table? The file to be removed is not associated with any component, but generated by the application. Thanks

Ivan_mysammy
09-28-2010, 01:56 PM
Here's my solution:

senario: delete INSTALLDIR folder, all its subfolder and files during uninstallation

steps:

1. create an Installscript function:

#include "Ifx.h"
export prototype Fn_DeleteDir(HWND);
function Fn_DeleteDir(hMSI)
STRING strInstallDir;
NUMBER nSize;
begin
nSize = 256;
MsiGetProperty(hMSI,"INSTALLDIR",strInstallDir,nSize);
DeleteDir (strInstallDir, ALLCONTENTS);
end;

2. create a custom action to call above function, settings:

Function Name: Fn_DeleteDir
Return Processing: Synchronous
In-Script Execution: Immediate Execution
Execution Scheduling: Always execute
Install Exec Sequence: After InstallFinalize
Install Exec Condition: REMOVE = "ALL"

leave other settings by default

end steps.

My installscript code is not strong enough and I am not sure the custom action settings are appropriate, anyway it works as I expect.

reference:
http://community.flexerasoftware.com/showthread.php?t=193676&highlight=remove+files

Rouslan
09-29-2010, 01:41 AM
Rouslan, for the first method, how to set "Component" field in RemoveFile table? The file to be removed is not associated with any component, but generated by the application. Thanks
You can set any component. For examle:
FileKey: MyRandomKey123 (any uniq key for RemoveFile table)
Component_: MyExistingComponent (any existing component)
FileName: myFileToDelete.tmp (exact file name)
DirProperty: MYDIRECTORY (directory key from Directory table for your file location)
InstallMode: 2 (Remove only when the associated component (MyExistingComponent) is being removed)

Ivan_mysammy
10-05-2010, 01:17 PM
You can set any component. For examle:
FileKey: MyRandomKey123 (any uniq key for RemoveFile table)
Component_: MyExistingComponent (any existing component)
FileName: myFileToDelete.tmp (exact file name)
DirProperty: MYDIRECTORY (directory key from Directory table for your file location)
InstallMode: 2 (Remove only when the associated component (MyExistingComponent) is being removed)

Thanks Rouslan, your method works!