Set APPDIR at runtime - Advanced Installer Community
tiktin
Posts: 2
Joined: Tue Mar 30, 2010 10:39 pm

Set APPDIR at runtime

I would like to set APPDIR at runtime based on an examination of the registry and file system.
The installer is for a component that could be installed with several other products or by itself.
If another of our products is installed, I want to locate it and offer that location as the default in the
folder dialog.

I have a JScript (not JavaScript) script that does the right thing when executed by wscript.exe (it
gets the right value), but I have not been able to get it to run as an attached custom action, which is
what I thought would be needed.

Any thoughts on another way to set APPDIR at runtime? Or how to make the JScript script work as
an attached custom action? I'm using AI version 6.1.1 if it matters.

Dave
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Set APPDIR at runtime

Hi Dave,

As with all custom actions, it is recommended you avoid using scripts, and use DLL custom actions instead. Using JScript does not guarantee it will work on all machines as the available scripting host may not support it. VBscript is more commonly used amongst installers, it is better than JScript but still inferior to a DLL custom action with respect to compatibility.

Setting APPDIR to a location from the registry shouldn't be that hard. You don't need a custom action for this:
- on the Search page, create a search and name it APPDIR2 so it stores the search result in APPDIR2.
- on the Custom Actions page use a "Property Set with Formatted" to set APPDIR to APPDIR2's value. This custom action is condition only to assign it if APPDIR2 is set, i.e the search was successful.

Attached is a sample project that demonstrates this. Let me know how this worked for you.

Best regards,
Gabriel
Attachments
APPDIR_FROM_REG_EXAMPLE.aip
(9.65 KiB) Downloaded 1333 times
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
tiktin
Posts: 2
Joined: Tue Mar 30, 2010 10:39 pm

Re: Set APPDIR at runtime

GabrielBarbu wrote: As with all custom actions, it is recommended you avoid using scripts, and use DLL custom actions instead. Using JScript does not guarantee it will work on all machines as the available scripting host may not support it. VBscript is more commonly used amongst installers, it is better than JScript but still inferior to a DLL custom action with respect to compatibility.
Microsoft claims that JScript is supported by default on all platforms along with VBScript, so I thought it would work, and it's what I'm more familiar with.

http://msdn.microsoft.com/en-us/library/ms974627.aspx
http://blogger.ziesemer.com/2008/01/use ... cript.html

I'll look into DLL custom actions for future reference.
GabrielBarbu wrote: Setting APPDIR to a location from the registry shouldn't be that hard. You don't need a custom action for this:
- on the Search page, create a search and name it APPDIR2 so it stores the search result in APPDIR2.
- on the Custom Actions page use a "Property Set with Formatted" to set APPDIR to APPDIR2's value. This custom action is condition only to assign it if APPDIR2 is set, i.e the search was successful.
I knew there had to be an easier way! Thanks for your prompt response.

Dave
invalidptr
Posts: 79
Joined: Thu Nov 18, 2010 7:10 pm

Re: Set APPDIR at runtime

Thanks for the example code for reading the path from the registry. I'm using it in AI 8.0.2. I'm having a problem with it... I want to expose to the user the database's path and filename in the registry.

When I set the type to "The value contains a path to a directory" I get: c:\ I expected: c:\myproject\
When I set the type to "The value contains a path to the file" I get: c:\myproject\ I expected: c:\myproject\database.mdb
When I set the type to "Retrieve the raw value" I get: c:\myproject\database.mdb\ I expected: c:\myproject\database.mdb (without the trailing slash)

Is this the behavior you expect?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Set APPDIR at runtime

Hi,

What is the actual registry value? Also, how are you determining the search result? Are you using the test search feature or you are verifying the APPDIR path? Please note that APPDIR is automatically ended with a backslash, no matter what value it has.
When I set the type to "The value contains a path to a directory" I get: c:\ I expected: c:\myproject\
When using this option the search should return the raw value ended with a backslash.
When I set the type to "The value contains a path to the file" I get: c:\myproject\ I expected: c:\myproject\database.mdb
When using this option the search should return the folder path in which the file is placed (the file parent path).
When I set the type to "Retrieve the raw value" I get: c:\myproject\database.mdb\ I expected: c:\myproject\database.mdb (without the trailing slash)
When using this option the search should return the actual value.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
invalidptr
Posts: 79
Joined: Thu Nov 18, 2010 7:10 pm

Re: Set APPDIR at runtime

The actual registry value is: c:\myproject\database.mdb

I don't want to overly quote your reply. But given this piece of information would you agree or disagree that I'm seeing the correct behavior? In the order they appear:

1. Give what you said I should have gotten c:\myproject\database.mdb\ instead I got c:\
2. Works correctly. I interpreted "value contains a path to a file" as "I want that part too" but I realize now it means, "there's a filename in the path. Strip it out when reading"
3. Is it a bug that I'm getting the training slash? I'm not using APPDIR to store this variable. But is it of similar vintage to invoke the "APPDIR is automatically ended with a backslash" rule?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Set APPDIR at runtime

Hi,

How are you determining the search result? What are the values retrieved during install? Also, can you please export the registry key in a REG file and send it to support at advancedinstaller dot com so we can test it?

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
invalidptr
Posts: 79
Joined: Thu Nov 18, 2010 7:10 pm

Re: Set APPDIR at runtime

I think I've come to a better understanding of this feature. I've attached an AIP file for you to try it out yourself (it only contains this test case). Run setup until you get to the FolderDlg to see the demo. I'm looking at a registry value everyone has that contains a filename. On the install parameters tab you'll want to change the default path if you don't have a z:\ drive. I did this to know I was seeing all three values change. My raw registry value is: C:\Documents and Settings\Administrator\Favorites\Links\Suggested Sites.url

* Because it contains a filename "The value contains a path to a directory" fails and just returns the root of the drive C:\. Note that it's not the default (which is why I specified my z:\ drive so I knew I wasn't seeing the default value). Is this expected behavior?

* "The value contains a path to the file" works as expected. Because it know it contains a filename, AI strips the filename off C:\Documents and Settings\Administrator\Favorites\Links\

* "Retrieve the raw value" returns C:\Documents and Settings\Administrator\Favorites\Links\Suggested Sites.url\ Note the trailing slash. While this isn't APPDIR it is a Path Edit control. So it isn't so much APPDIR gets a trailing slash as much as a Path Edit control does (Do you agree?).
Attachments
PathSetByRegistry.aip
(12.04 KiB) Downloaded 698 times
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Set APPDIR at runtime

Hi,
Because it contains a filename "The value contains a path to a directory" fails and just returns the root of the drive C:\.
Actually it returns nothing. The search result is empty. On our test machines your dialog shows "z:\". This is a normal behavior when Windows Installer cannot resolve the search (for example the path cannot be interpreted as a folder path).
"Retrieve the raw value" returns C:\Documents and Settings\Administrator\Favorites\Links\Suggested Sites.url\ Note the trailing slash.
The search returns the path without a trailing backslash. The backslash is added automatically by Windows Installer to any path stored in APPDIR. This happens for all folders used in your installer.
While this isn't APPDIR it is a Path Edit control. So it isn't so much APPDIR gets a trailing slash as much as a Path Edit control does (Do you agree?).
The edit control simply shows the APPDIR property value. The backslash is not added by the installer UI, it's added by Windows Installer inside APPDIR.

So if you set APPDIR to:

Code: Select all

C:\Documents and Settings\Administrator\Favorites\Links\Suggested Sites.url
Windows Installer will modify during file costing to:

Code: Select all

C:\Documents and Settings\Administrator\Favorites\Links\Suggested Sites.url\
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
invalidptr
Posts: 79
Joined: Thu Nov 18, 2010 7:10 pm

Re: Set APPDIR at runtime

I just spent a 1/2 hour trying to get this to work. My issue? I only had it under InstallExecuteSequence and not under InstallUISequence. Sigh. From you're experience, what am I not getting? Given that I need to read the registry for the UI, do I only need it in InstallUISequence and remove it from InstallExecuteSequence.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Set APPDIR at runtime

Hi,

InstallUISequence handles the package UI and InstallExecuteSequence handles the actual installation process. If you want your custom action to affect the UI (for example modify a displayed string), we recommend adding it in InstallUISequence. You can also share this action with InstallExecuteSequence to make sure that it runs even for silent installations. In this case make sure it uses the Execute only once if present in both sequence tables option.

InstallExecuteSequence should be used exclusively (i.e. the action is not added to InstallUISequence) only when the action doesn't not affect an UI element.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Jis
Posts: 51
Joined: Thu Dec 12, 2013 6:02 am

Re: Set APPDIR at runtime

Hi..

I have a similar issue too, I want to set APPDIR2 path during runtime.
My installer installes a file, FileA, at the begining of the installation. I want to set my APPDIR2 path to this files path.How do I do this?

Please help me out.

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

Re: Set APPDIR at runtime

Hello Jis,

To achieve what you want you should just search for the parent folder of the related file. Please take a look on the "Find the folder which contains a file" tutorial section to see how this can be done.

Then, in our "Custom Actions" page you should add a "Set property value" custom action which will set the "APPDIR" property to "APPDIR2" property value. This custom action should use the following condition: APPDIR2. This way the original installation path will be changed only if the searched file was found.

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

Return to “Common Problems”