borislaa
Posts: 16
Joined: Wed Oct 05, 2005 11:35 pm
Location: Nice, France

How to install an existing file (replace the existing one)

Hello,

I have to put an existing file on the target PC. Even if the file exists or not I must replace the existing one with the one in my msi file.
I put this file in a separate component and I check the Permanent checkbox to be not deleted on uninstall.
But I see that the existing file is not replaced on installation ... It is not a read-only file. I check this ...
Can you suggest me a custom action to delete the file if exists on the target PC to be able to copy the new one.
I don't found the right syntax to delete a file with VBScript ...
I put the following code in a vbs file on my hard disk and I create a InstallUISequence=>Begin=>New Attached Custom Action
and in Function name I put Main():
Function Main()
Dim fso, demofile
Set fso = CreateObject("Scripting.FileSystemObject")
demofile = Session.Property("RVDEBUG_INSTALL") + "\\etc\\RVI-ME-USB-Philips.brd"
fso.Delete demofile, true
End Function
but its not working
I have an error message:
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.
Thanks a lot
Alexandre
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

Hi,

If a file exists at the target location whether it will be replaced or not depends on the file versioning rules:

http://msdn.microsoft.com/library/en-us ... _rules.asp

Regarding the script, it has several errors. Here is a working version.

Code: Select all

Function Main
   Dim fso
   Dim filespec
   filespec = Session.Property("APPDIR") + "subFolder\test.txt"   
   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.DeleteFile(filespec)   
End Function
You should replace APPDIR with the property containing the path to the directory where the "subFolder\test.txt" should be found. The custom action should be place after the CostFinalize action, when all the properties values have been resolved. You should ignore the return code as the DeleteFile method returns error is no file is found at the location indicated by filespec.

However, Advanced Installer makes the removal of the file a lot easier. You don't need a custom action. Just use the New File Removal toolbar button in the File and Folder page. Place the New File Removal item in the folder where you expect to find the file you want to delete.

Regards,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com
borislaa
Posts: 16
Joined: Wed Oct 05, 2005 11:35 pm
Location: Nice, France

Thanks Mihai,

Very useful help, thanks a lot.
Just a little question:
With the Removal action in File and Folder page, is there any order to execute the different actions:
-First all removal items
-After all add items
because I want to remove a file that I will add in the same time, so the order is very important.
I tested and it seems good, but is there any rules for the order?
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

Hi,

The file removal occurs on the RemoveFiles standard action. This standard action comes before the InstallFiles action, which copies the files. Therefore you can be sure that the installation will go on as you require.

Regards,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com
borislaa
Posts: 16
Joined: Wed Oct 05, 2005 11:35 pm
Location: Nice, France

Hi,

In fact the solution with RemoveFiles standard action is not good for my case, because I want to remove a file which directory path is stored in env variable. I think that when it try to remove the file, the folder is not known yet, and the file is not removed. (I take the folder name with custom action - Property set with formatted)
Firstly, I tested with a small example and it worked fine, but when I tested with my real application - a huge tree of files, it is not working ...
I will try with the script soluton. Thanks
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

Hi,

In order for the folder name to be known when you try to remove the file, you should schedule the Property Set with Formatted before the RemoveFiles standard action. For example you could place it on InstallInitialize.

Also, instead of a Property Set with Formatted you could try to use a Directory Set with Formatted type of custom action, to set the value of the property.

Regards,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com
borislaa
Posts: 16
Joined: Wed Oct 05, 2005 11:35 pm
Location: Nice, France

Hello Mike,

I schedule the Property Set with Formatted before RemoveFiles standard action in Begin section.
When I tried to put it in InstallInitialize as Directory Set with Formatted, there was an exception: Could not access network location Your Value ...
But I think the problem was that when I create the Remove Standard action, I must select the associated component. During the installation of this component, my remove action will be activated I think.
So I putted the folder where the file must be removed as component for the remove action and it seems to work fine.

In the Begin section the Directory Set with Formatted is not selectable, so I cannot create it, but with Property Set it seems to work ...

I have another problem, but I will post a new post I think, because it's not related directly with this post.
Thank you

Return to “Common Problems”