vakbijevs
Posts: 12
Joined: Wed Nov 15, 2006 3:43 pm

How to remove non-empty application folder after uninstall?

I have one question, how i can remove folder if after uninstall folder not removed because not empty (some application runtime files still in folder). Do you have an method to remove folder if not empty?
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

To remove that non empty folder you can create a VBS custom action scheduled under "InstallFinalize" standard action. To execute this custom action only when the package is uninstalled use this "Execution Condition": (REMOVE="ALL")

Here is the VBS code for the custom action:

Code: Select all

Function removeDir()
   Dim pathToFolder, smallPath
   Set objFS = CreateObject("Scripting.FileSystemObject")
   pathToFolder = Session.Property("PROPERTY")   
   smallPath=Left(pathToFolder,Len(pathToFolder)-1)      
   If (objFS.FolderExists(smallPath)) then
      objFS.DeleteFolder smallPath, true      
   End if
End Function
Where the PROPERTY indicate to the folder you want do be deleted.

Hope this helps.

Regards,
Gigi
______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
vakbijevs
Posts: 12
Joined: Wed Nov 15, 2006 3:43 pm

Not clear!

Ok, I have "InstallFinalize" what I should add next?
New attached custom action or New custom Action -> Script inline?

Can you describe step by step? :?
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

Copy the code from the previous post in a .vbs file. Switch to "Custom Actions" page and add a "New Attached Custom Action" under "InstallFinalze" standard action. Browse for the .vbs file created.

In the "Function Name" field type: removeDir. As "Execution Condition" use (REMOVE="ALL").
Also not that the PROPERTY indicate to the folder you want do be deleted. If you use a hard coded path replace "Session.Property("PROPERTY")" with the hard coded path.

To read more about how to use custom actions with Advanced Installer please see:
http://www.advancedinstaller.com/user-g ... -page.html

Regards,
Gigi
_______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
vakbijevs
Posts: 12
Joined: Wed Nov 15, 2006 3:43 pm

Cool! Thanks! :oops:
joncrlsn
Posts: 4
Joined: Fri Jan 12, 2007 11:02 pm

How to set property to install dir

Hi Gigi,

Which page discusses how to set Session.Property("PROPERTY") to the current installation directory? (I would hard-code the path, but the user is allowed to pick their own installation directory). I've been looking for several days and haven't found anything on how to set a property to the installation directory.

Thanks!

Jon
vakbijevs
Posts: 12
Joined: Wed Nov 15, 2006 3:43 pm

APPDIR - installation folder

Code: Select all

Function removeDir() 
   Dim pathToFolder, smallPath 
   Set objFS = CreateObject("Scripting.FileSystemObject") 
   pathToFolder = Session.Property("APPDIR")    
   smallPath=Left(pathToFolder,Len(pathToFolder)-1)      
   If (objFS.FolderExists(smallPath)) then 
      objFS.DeleteFolder smallPath, true      
   End if 
End Function
Works ok for me
raja
Posts: 2
Joined: Thu Aug 30, 2007 7:36 pm

hi i have a folder called 'data' which i want to delete when the program is uninstalled!!

this would be very important to users of this program.

I tried the above..

Code: Select all

Function removeDir() 
   Dim pathToFolder, smallPath 
   Set objFS = CreateObject("Scripting.FileSystemObject") 
   pathToFolder = Session.Property("PROPERTY")    
   smallPath=Left(pathToFolder,Len(pathToFolder)-1)      
   If (objFS.FolderExists(smallPath)) then 
      objFS.DeleteFolder smallPath, true      
   End if 
End Function
but it didnt work properly. Almost near the end of the uninstall it geives an error that it the vbs script can not be executed. the file is called uninstallcode.vbs which was in mydocuments. it was added under installfinalize as an attached custom action....

i did not set anything under the property

so a few questions...
does the vbs file get included in the installer?
is the vbs code above correct?
any easier way to delete installed folder upon uninstall?
in the function name is 'removeDir' ok or does it have to be 'remove Dir()'
raja
Posts: 2
Joined: Thu Aug 30, 2007 7:36 pm

just sorted it out

the poster should have made it clear that the PROPERTY in the vb script needed to be set to APPDIR or the path to the folder!


Session.Property("APPDIR")

i was looking in under the property button in 'execution condition'
fd1
Posts: 21
Joined: Fri Sep 02, 2005 8:12 pm

easier way to do it is to add a custom action "EXE with Working Dir" under "Uninstall" with:

Working Dir=SystemFolder
Full Path=cmd.exe /Q /C "rd /S /Q "[APPDIR]""
GiffRansom
Posts: 2
Joined: Fri Jun 06, 2008 4:43 pm

Re: How to remove non-empty application folder after uninstall?

Working Dir=SystemFolder
Full Path=cmd.exe /Q /C "rd /S /Q "[APPDIR]""
The above code doesn't work in the case of an installation to a custom path. It is trying to remove the folder at the original path and not the one the customer chose. Any ideas on how to address this?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to remove non-empty application folder after uninstall?

Hi,

I cannot reproduce this behavior on my test machines (the custom path is recognized correctly). Did you set the custom actions as "Immediate"?

Please try using the custom action in the first posts (the VBScript code). Note that this custom action tries to remove the folder which has the path in the property. Therefore, if you are using APPDIR for the installation path, the custom action will remove everything in APPDIR (the one set by the user).

If this custom action doesn't work either, please send us the AIP you are using to support at advancedinstaller dot com so we can investigate it.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
bball125
Posts: 4
Joined: Tue Jan 20, 2009 10:39 pm

Re: How to remove non-empty application folder after uninstall?

So I tried both ways and when I attach the VB script to the installfinialize it doesn't do anything, if I do the cmd.exe command it crashes the uninstall. Any other ideas? This could have changed since this post was from a couple years ago. What I need is to be able to delete the folders created during install (and everything in them) when I uninstall the application. Any other ideas?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to remove non-empty application folder after uninstall?

Hi,

Please try following the Remove a file or a folder during installation how-to for your project. If it doesn't work, please give me more details about the exact problems you are encountering.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pfitom
Posts: 3
Joined: Tue Sep 21, 2010 9:37 pm

Re: How to remove non-empty application folder after uninsta

I created the vbs file as above with property set to APPDIR. I'm using app installer version 8.6. Under Custom Actions I created a new attached custom action under InstallExecuteSequence->Uninstall. I set the source path to the vbs file, set function name to removeDir. When I run the uninstall I get an error message "There is a problem with this Windows Installer package. A script required for this install to complete could not be run...."

What's going on?

Thanks,
Tom

Return to “Feature Requests”