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!

asantia
Posts: 2
Joined: Thu Sep 25, 2014 7:13 pm

Look for and copy, if exist, instance specific files

I have a MSI installer which I want to modify.

I need it to look for a specifically named folder (call it "custom" for this example) included alongside the MSI and, if found, copy that folder to the installation location.
( C:\SetupFiles\MyProgram.msi | C:\SetupFiles\custom )
The "custom" folder will contain files specific to the computer the MSI is being installed on and will be different for each we run it on.
I want to copy the entire folder and place it as a child-folder under where the MSI is installing the program files to.
( C:\ProgramFiles\MyProgramDir | C:\ProgramFiles\MyProgramDir\custom )

I have VB code that illustrates what I want done, but I don't want to use VB code to preform what I believe the MSI can do on its own.
(My need sounds similar to this: http://www.advancedinstaller.com/user-g ... -file.html)

Code: Select all

Function CustomCopy()
	Dim instPath, customPath, folder
	instPath = Session.Property("APPDIR")
	customPath = Session.Property("CUSTOMDIR")

  LogVBS "------ CustomCopy ------"
  LogVBS "  APPDIR=" & instPath
  LogVBS "  CUSTOMDIR=" & customPath

	Set fsObj = CreateObject("Scripting.FileSystemObject")

	' CUSTOMDIR folder exist?
	If fsObj.FolderExists(customPath) Then
	  LogVBS "  CUSTOMDIR exists"
		If fsObj.FolderExists(instPath) then
  		LogVBS "  APPDIR exists."
			Set folder = fsObj.GetFolder(customPath)
	  	LogVBS "  Copying CUSTOMDIR into APPDIR."
			folder.Copy instPath, true
	  	LogVBS "  Copy complete."
		Else
  		LogVBS "  ERROR: APPDIR doesn't exist."
		End if
  Else
    LogVBS "  CUSTOMDIR missing, nothing to copy."
  End if
End Function
How can I setup a CustomAction within the MSI to accomplish this?
I need to make sure this will work for deployment via a Computer GPO, so it must obtain the correct permissions to write.

Thanks.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Look for and copy, if exist, instance specific files

Hello and welcome to our forums,

Thank you for your interest in Advanced Installer.

You are right this can be done without a custom action. Let us store the path to your folder in a property called XMLSOURCE. What you need to do is to follow these steps:
1. on "Install Parameters" page set XMLSOURCE property to "C:\"
2. on "Files and Folders" page add a new property based folder. Select XMLSOURCE as the property from the dialog that pops up.
3. from the directory tree select the folder in which you want the contents of the XMLSOURCE folder to be installed. For our purpose let's just select "Application Folder"
4. add a new "File Operation->File copy/move". On the "Edit File Copy/Move" dialog, make the following settings:
  • Source File
    Name : *
    Folder: XMLSOURCE
    Destination File
    Name: <leave blank>
    Folder: <leave this as is>
    Properties:
    Component: <select the component which should contain the file operation>
    Operation: Copy
5. on the "Custom Actions" page, under "Wizard Dialogs Stage -> Searches" actions group add a new "Set installer property" custom action with sequence with the following settings:
  • Property: XMLSOURCE
    Value: [SOURCEDIR]testFolder
Replace 'testFolder' with the name of you folder.
6. select the above added custom action, and while keeping the [SHIFT] key pressed, drag and drop it under "Install Execution Stage -> Searches" actions group (the custom action will be shared between both execution stages)

During installation, if the folder (residing alongside the setup package) is empty or does not exist, then the file copy operation won't copy anything in the destination folder.

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
asantia
Posts: 2
Joined: Thu Sep 25, 2014 7:13 pm

Re: Look for and copy, if exist, instance specific files

Thanks for the info.
That seems to work ok.

One further question...
How can I have the installer set a variable "WAIT" equal to "true" if my "custom" directory is found/exists?
(In your example what I want to check exists would be [SOURCEDIR]testFolder. For my use I renamed it to [SOURCEDIR]custom.)
I would like this to happen before the move operation.

Thanks.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Look for and copy, if exist, instance specific files

Hello,

You're welcome.

If you want to set an installer property (i.e. "WAIT") when your "custom" folder exists alongside the MSI setup, then you can use a folder search (CUSTOM_PROP) to check for your "custom" folder. Then, based on your folder search result (which is stored in the search associated property - CUSTOM_PROP) you can use a "Set installer property" custom action which will set the "WAIT" property to "true" or not.

Here are the steps to proceed:
1. go to "Search" page and add a new search (CUSTOM_PROP)
2. from its context menu choose "Add Location -> Folder"
3. in the "Directory Properties" right pane set the following:
  • Path: [SOURCEDIR]custom
    Depth: 0
4. go to "Custom Actions" page and under "Wizard Dialogs Stage -> Searches" actions group add a new "Set installer property" custom action with sequence with the following settings:
  • Property: WAIT
    Value: true
    Condition: CUSTOM_PROP
6. select the above added custom action, and while keeping the [SHIFT] key pressed, drag and drop it under "Install Execution Stage -> Searches" actions group (the custom action will be shared between both execution stages)
7. build and test the project

If you have any questions let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”