Deleting Files/Folders in a Custom Action - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Deleting Files/Folders in a Custom Action

Hello everyone.

To delete files/folders in a custom action one can use VBScript, using "FileSystemObject.DeleteFolder path, force", However, if the file/folder is locked/in use this operation fails and makes Windows Installer report an error in the uninstallation of our software.

Is there a mechanism in AI to delete files/folders from inside a custom action's script in a way "compatible" with Windows Installer, meaning it tries to remove the items and schedules the in-use items to be deleted upon next reboot, or something similar?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Deleting Files/Folders in a Custom Action

Hi,

What you need can be done by using the "Files and Folders" page. Here are the steps:
- in the "Files and Folders" page double-click the folder you want to remove
- in the "Edit Folder" dialog go to the Remove tab
- check the "Remove folder (only if empty)" option
- select the component which will control the folder removal

If you need to remove a custom folder which is not present in the "Files and Folders" page, you can create a property-based folder. Note that the folder will not be removed if its not empty.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Deleting Files/Folders in a Custom Action

Hello Cosmin,

unfortunately the folder will contain "random" files generated at runtime of the application (Application Data).

I will have to write script code that tries to delete the files and folders, have error handling when they are in use, and live with some files and live with the fact that (non empty or in use) folders will remain on the computer, won't I?



With best regards

Clemens Anhuth
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Deleting Files/Folders in a Custom Action

Hi,
I will have to write script code that tries to delete the files and folders, have error handling when they are in use, and live with some files and live with the fact that (non empty or in use) folders will remain on the computer, won't I?
I'm afraid that Windows Installer doesn't support another way of removing a folder. Therefore, I'm not sure if there is a solution for removing the files. Eventually, if the files cannot be removed you can inform the user about them through a message box.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Deleting Files/Folders in a Custom Action

Hello Cosmin,

I am blissfully Windows Installer ignorant, but stumbled over this anyway regarding the "RemoveFile table":

http://msdn.microsoft.com/en-us/library/aa371201.aspx

(What is interesting is the fact that wildcards can seemingly be used.)

Can this RemoveFile table generally be modified only upon creation of the installer, or can it be altered at runtime of the uninstallation, too?


With best regards

Clemens Anhuth
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Deleting Files/Folders in a Custom Action

I forgot to mention this URL, too:

http://geekswithblogs.net/ajshurts/arch ... 48388.aspx

I might be able to know the names of the folders (and their sub-folders, etc.) in advance, but the names of the files are completely random.

Can I specify the entries in the RemoveFile table in AI somewhere?

With best regards

Clemens Anhuth
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Deleting Files/Folders in a Custom Action

Drilling further I found this:

http://msdn.microsoft.com/en-us/library ... S.85).aspx

"Accessing a Database or Session from Inside a Custom Action"

I'll keep digging...
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Deleting Files/Folders in a Custom Action

Hi,

Please note that these articles refer to the File Removal file operation. Although it can remove multiple files by using wildcards, you must provide the exact path of the folder which contains these files. Also, if the files are in use and they cannot be removed, Windows will remove them after a reboot. However, the folder which contains the files will not be removed (it is not empty when Windows Installer tries to remove it).

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”