Clutch
Posts: 12
Joined: Sat Oct 20, 2018 4:23 am

Install some files outside the APPDIR and using CheckBox

Sat Oct 20, 2018 2:58 pm

Question 1
Can AI copy or move specific files that are included with my app to a custom location that is different than the app install location (APPDIR)? If so, I have not been able to find a way.

For example, I created a “3rd-party” app that works with a program already installed. Let’s call that the main program. First, the user can install my App to any location they desire via the AI Folder Dialog. That works fine.

Once that is done several other files that are included are to be copied (moved actually), from the installed location to a sub-folder found on the main program. There can be several versions of the main program so I am using a custom search (INSTALL_PATH) which uses the registry to find the path of the main program.

I have tried the copy/move operation with now success. I have tried a Custom Action inline vbscript such as:
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile Session.Property("APPDIR") & “*. DLL", Session.Property("INSTALL_PATH") & “SUBFOLDER1\SUBFOLDER2\SUBFOLDER3\"

I have also tried a custom action using an attached vbscript file using variations of the code above. And just to add I have searched these forums and read the User’s Guide before I submitted this.
Where am I going wrong?

Question 2
I want the user to select a Checkbox to determine which version of the main program they already have installed (this is not my App). Then I plan to use a VBscript IF THEN statement such as:

IF the Checkbox is “checked” AND the session.property(INSTALL_PATH) is true THEN…
(to install some of my files to that main apps location.)

What do I pass on to determine if the Checkbox has been checked? It appears it would be the Value property Selected=true? How would I state that?

Thank you for your time.

Catalin
Posts: 6541
Joined: Wed Jun 13, 2018 7:49 am

Re: Install some files outside the APPDIR and using CheckBox

Mon Oct 22, 2018 3:41 pm

Hello and welcome to our forums,

From what I can see, you are trying to move all the .dll files from your application directory to another directory. This can be done in two different ways:

1- You can use our predefined support for the file copy/move operation. For more information about this, you can have a look on the following articles:

- https://www.advancedinstaller.com/user- ... tions.html

- https://www.advancedinstaller.com/user- ... ialog.html

I am not sure why you did not get this working. Could you please show me a screenshot of how you configured the operation?

2- You can do this through a custom action. In order to achieve this, we can use a "PowerShell inline script" custom action. Please proceed as follows:

- Go to "Custom Actions" page and add a "PowerShell inline script" with sequence. In order to add a custom action with sequence, you can simply press the "Add custom action with sequence" button which is placed to the right side of the custom action's name.

- Now please schedule your custom action after the "Finish Execution" action group. To do so, simply drag and drop it after the earlier specified action group.

- Now introduce the following script under the "Your code goes here" comment:

Code: Select all

$appDir = AI_GetMsiProperty APPDIR
$installationPath = AI_GetMsiProperty INSTALL_PATH
Move-Item -Path "$appDir\*.dll" -Destination "$installationPath"
In what regards the checkbox, its value can be either "CheckBox" or "" (null). For example, if you add a checkbox to one of your dialogs, on the right pane, under "Properties", you can see that there is an installer property which will store the value of the checkbox. The default names for these are: CHECKBOX_PROP, CHECKBOX_1_PROP, etc.. However, you can easily change the property name which stores the value of the checkbox.

So, with that being said, to check a if a checkbox is checked, you can use the following statement:

CHECKBOX_PROP = "CheckBox"

Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Clutch
Posts: 12
Joined: Sat Oct 20, 2018 4:23 am

Re: Install some files outside the APPDIR and using CheckBox

Wed Oct 24, 2018 8:00 pm

Thank you for such a detailed response. As a test, I was able to get my first question answered with the following inline code:

# Block for declaring the script parameters.
Param()

# Your code goes here.
$appDir = AI_GetMsiProperty APPDIR
$installationPath = AI_GetMsiProperty INSTALL_PATH + "\Sub-Dir1\Sub-Dir2\Sub-Dir3\"
Move-Item -Path "$appDir\*.bgl" -Destination "$installationPath"

With that working, I have been trying to solve my 2nd question adding the IF statement checking on if my CheckBox has been checked but no luck. I have tried:

# Block for declaring the script parameters.
Param()

# Your code goes here.
If (CHECKBOX_PROP="Checkbox")
{
$appDir = AI_GetMsiProperty APPDIR
$installationPath = AI_GetMsiProperty INSTALL_PATH + "\Sub-Dir1\Sub-Dir2\Sub-Dir3\"
Move-Item -Path "$appDir\*.bgl" -Destination "$installationPath"
}

I have also tried many different renditions of my added IF statement without success like:

$propValue = AI_GetMsiProperty CHECKBOX_1_PROP
If ($propValue = "CheckBox") #also have tried ="True", <>"", ="1"

I am sure the answer is staring me in the face but it is not "clicking" for me :( Will still keep researching the forums.

Catalin
Posts: 6541
Joined: Wed Jun 13, 2018 7:49 am

Re: Install some files outside the APPDIR and using CheckBox

Thu Oct 25, 2018 9:40 am

Hello,

You're always welcome.

I am glad I could be of help.

In what regards your second question, the second approach is almost complete. Here is how your if statement should look:

Code: Select all

if($propValue -eq "CheckBox"){

Your Code Goes Here

}
Please keep in mind that in PowerShell, the comparison is made as it follows:

"-lt" --> lower than

"-gt" --> greater than

"-eq" --> equal to

Please let me know if this helps.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Clutch
Posts: 12
Joined: Sat Oct 20, 2018 4:23 am

Re: Install some files outside the APPDIR and using CheckBox

Thu Oct 25, 2018 8:21 pm

Again Catalin,

II must say the support here is superb. This is my first time with PowerShell as I normally code with VBscript. That simple change got the script working! So this leads to hopefully two ending questions:

1. Could I have written the same inline script with VBscript? I assume AI allows this (and will probably try), but just wanted to confirm.

2. Is it possible to "deactivate" (place on hold), certain Custom Actions or Searches within a project so they do not run (or be compiled)? I noticed I was writing several versions of my scripts to test them out but the only way I could see to test something new was to delete the current script or copy it over to Notepad and then copy back if I wanted to try it again.

Clutch

Catalin
Posts: 6541
Joined: Wed Jun 13, 2018 7:49 am

Re: Install some files outside the APPDIR and using CheckBox

Fri Oct 26, 2018 8:37 am

Hello Clutch,

First of all, thank you for your feedback.

You are always welcome, I am glad I could help you achieve what you wanted.

In what regards your questions:

1) Yes, you can write the same script as a VBScript by using the "Execute inline script code" custom action. I have chosen the PowerShell approach because my VBScript knowledge is limited.

2) I am afraid that you can not manually "disable" your scripts, but you can, for example, condition them so they will never execute. To do this, we can use a condition that will always be evaluated as false. For instance, we can create a new public property in the "Install Parameters" page like this:

Name: MY_CONDITION
Value: 1


Now, we can go in "Custom Actions" page and condition the custom actions as it follows:

Code: Select all

MY_CONDITION = "0"
This way, the condition will always be evaluated as false and the custom action will never run. If you want it to run, simply change the condition to "MY_CONDITION = "1"" or simply remove it.

Hope this helps!

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”