blak3r
Posts: 8
Joined: Wed Jun 17, 2009 7:40 pm

SOLVED: Overwrite a installed file with 1 located in MSI dir

I'd like to let customers customize the files which get installed by letting them putting a logo1.gif file in the same directory as the MSI.
During a commit phase I'd like for it to check for the existence of such a file and if it exists copy it to the install directory.

I could create a hardcoded list of files which could be copied... and then write a bat or vbs script todo this but wanted to see if there was a way to do this built in to advanced installer.
Last edited by blak3r on Tue Jun 30, 2009 12:50 am, edited 1 time in total.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Overwrite a installed file with one located in MSI directory

Hi,

To copy the file you can try using the approach explained in the Install an user specific file how-to. The file copy operation can use wildcards, so it should be easy to configure one or more operations for the files you want.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blak3r
Posts: 8
Joined: Wed Jun 17, 2009 7:40 pm

Re: Overwrite a installed file with one located in MSI directory

Is there anyway this method could be used to overwrite a file which is installed?
I want to be able to overwrite a default file.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Overwrite a installed file with one located in MSI directory

Hi,

When using a file copy operation Windows Installer uses the file versioning rules. If this doesn't work the way you need, you can try using a custom action to copy the file. You can find some sample VBScript code here.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blak3r
Posts: 8
Joined: Wed Jun 17, 2009 7:40 pm

Re: Overwrite a installed file with one located in MSI directory

Cosmin,

I'm having some issues with writing a custom action to perform a simple copy action... observations:

a) Function Name: doesn't seem to work. I always get an error. I found if i didn't use a function name at all the script would run. Documentation isn't very clear on this.

b) From the little documentation I could find. I got the impression that you could only pass "Formatted Type" arguments to an exe or dll. Is this true?

c) Going under the assumption that I wasn't going to be able to pass in arguments I looked at the Session object. The following script fails on line 2.
MsgBox "I'm in the script"
MsgBox Session.Property("APPDIR") <--- fails on this line.

If i can get a vbs script setup such that i can have two variables one with A) the directory the MSI is located in and b) The APPDIR I could knock this guy out.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Overwrite a installed file with one located in MSI directory

Hi,
Function Name: doesn't seem to work. I always get an error. I found if i didn't use a function name at all the script would run. Documentation isn't very clear on this.
A function name needs to be specified when using a C++ DLL custom action (the field becomes a combo which contains the available functions). However, this is optional when using a VBS file. For example if the code looks like this:

Code: Select all

Function MyFunction()
  'code
End Function
the "Function Name" field should be set to:

Code: Select all

MyFunction
If the VBScript doesn't use a function, the "Function Name" field should be empty.
From the little documentation I could find. I got the impression that you could only pass "Formatted Type" arguments to an exe or dll. Is this true?
An EXE custom action can receive arguments only through its command line, which can use hard-coded values or formatted elements. A C++ DLL custom action can access only installer properties through the MsiGetProperty and MsiSetProperty functions.
Going under the assumption that I wasn't going to be able to pass in arguments I looked at the Session object. The following script fails on line 2.
MsgBox "I'm in the script"
MsgBox Session.Property("APPDIR") <--- fails on this line.
I'm not sure why you are encountering this behavior. Can you please send us the .AIP (project) file, the VBScript file and a verbose log of the install process to support at advancedinstaller dot com so we can investigate them?

Note that the path of the folder which contains the MSI is stored in the SOURCEDIR property.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blak3r
Posts: 8
Joined: Wed Jun 17, 2009 7:40 pm

Re: Overwrite a installed file with one located in MSI directory

Thanks to cosmin I now have a working solution. In case anyone else is interested here is what you need to do.

Under the Custom Actions. Add the InstallFinalize "InstallExecuteSequence". Do this by right clicking in the Install Sequence area selecting "Show Standard Action" -> Before Finalization -> InstallFinalize. This adds a new folder. I'm not sure why... but this didn't work when I tried using the "Commit" InstallExecuteSequence.

Right click on the new folder and do new attached custom action. Select vbs as the type. Make sure you select "immediate Execution".

Here is the script i created. Modify the three copyFile("logo1.gif") lines to appropriate filenames for your installation.

Code: Select all

' file: customize.vbs
' description: this script runs as an attached installer script.  What it does it is
'              looks for files which are located in the same directory as the MSI.  If they
'              are found, it overwrites the one that is installed.  This allows customers to 
'              easily make different settings etc to customize their install build.
'
'              IMPORTANT: Must be run under "InstallFinalize" with immediate execution in order
'                         for the Session.Property("SOURCEDIR") variables to work.
dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
dim srcdir, destdir
dim srcfile, destfile

srcdir = Session.Property("SOURCEDIR")
destdir= Session.Property("APPDIR")

' List all files you want to copy here.
copyFile("logo1.gif")
copyFile("logo2.gif")
copyFile("app.config")


Function copyFile( theFile ) 
	srcfile = srcdir & theFile
	destfile = destdir & theFile
	'MsgBox "SRC: " & srcfile & "  DEST: " & destfile
	If filesys.FileExists(srcfile) Then
		 filesys.CopyFile srcfile, destfile, true
	End If
	'MsgBox "leaving copyFile"
End Function
You may also need to define the SOURCEDIR property. There is a tutorial somewhere which explained how to do this...

Return to “Feature Requests”