janderssen
Posts: 18
Joined: Tue Nov 20, 2007 7:19 am

Prevent a file from being un-installed at a users request

Hi,

We have a data file in the install, and is installed into Common Application Data. When the user has used our program, we dont want the file to be deleted at un-install automatically, But we would like this to be optional, based on asking the user first. This will also require the same question if the file already exists at install (ie asking the user to overwrite the existing file)

How would I best acheive this result.

Cheers
Jason
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,
When the user has used our program, we dont want the file to be deleted at un-install automatically, But we would like this to be optional, based on asking the user first.
This can be done by using a custom action. Here are the steps:
- go to the "Organization" page and for the component of the file set the "Do not register this component with Windows Installer" option
http://www.advancedinstaller.com/user-g ... rties.html
- this will make the installer to not remove the file during uninstall
- on the disk create a VBS file which contains this:

Code: Select all

strFilePath = Session.Property("PATH_TO_FILE")
set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strFilePath)
- in the "Custom Actions" page add the VBS file as an Attached custom action under "InstallExecuteSequence" -> "Uninstall"
- make sure that this custom action is set as Immediate
- this custom action uses the Property PATH_TO_FILE in order to find the file which will be deleted
- you can set this property to point to the file with a custom action
- now you need to create a custom action which prompts the user during Uninstall and sets a property according to the user's choice (this custom action can show a message box and depending on what button is pressed it sets the value of a property); it is recommended to use a C++ DLL for this custom action
- the property set by the user's choice will be used to condition the custom action which removes the file
This will also require the same question if the file already exists at install (ie asking the user to overwrite the existing file)
This can be done by using a property to condition the component of the file. This property can be set by a checkbox in one of the installation dialogs.

You can read more about the Dialog Editor feature here:
http://www.advancedinstaller.com/user-g ... ditor.html

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
janderssen
Posts: 18
Joined: Tue Nov 20, 2007 7:19 am

Thank you.
janderssen
Posts: 18
Joined: Tue Nov 20, 2007 7:19 am

Cosmin,

Is there a particular format for the VBS script. The un-installer always fails with :

"There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor."

All I did was create a vbs file, and pasted your code directly in it. Is there a certain format that the vbs script should maintain ?

As a note, if I try and run it from explorer (ie double click) it complains "Object Required : Session" Which I assume should be available when run from inside of the AI un-installation?

Cheers
Jason
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

Please note that you need to use a valid path as the value of the PATH_TO_FILE property. If the PATH_TO_FILE property is empty, the custom action fails because it cannot find the file which must be deleted.

Also, you can set a condition for the custom action to make sure that it doesn't run when the PATH_TO_FILE property is empty. This condition can be set to:

Code: Select all

PATH_TO_FILE
If the PATH_TO_FILE property contains a valid path and the custom action still fails, please send us a small test case (AIP, MSI and VBS file) which reproduces this behavior to support at advancedinstaller dot com so we can investigate it.

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

Return to “Common Problems”