set java command-line property based on Windows version - Advanced Installer Community

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!

toddpatt
Posts: 111
Joined: Fri Jan 08, 2010 1:36 am

set java command-line property based on Windows version

Greetings,

I'm using AI 7.6 build 27499

I have a Java product which accepts one argument from the command line - the absolute path to the working directory. On the "Virtual Machine" tab, I am setting the Command Line as: "%APPDATA%\[Manufacturer]\[ProductName]"

I am specifically not referencing the [AppDataFolder] property because that property is resolved at install-time. I need to resolve the path at run-time, so I am using the built-in Windows environment variable %APPDATA%. I realize that this type of configuration can leave behind garbage on the machine after the app is uninstalled, but that is acceptable behavior for us (I know, it violates installer "best practice").

What I would like to do is the following:
(a) If the Windows version is 2000 or XP, use %APPDATA% on the Java command line
(b) If the Windows version is Vista or 7, use %LOCALAPPDATA% on the Java command line

The reason I want to do this is because on Vista and 7, %APPDATA% resolves to "C:\Users\<user>\AppData\Roaming". My app is creating data which is specific to the current machine and should not be included in the user's roaming folder.

Is there a way to use either %APPDATA% or %LOCALAPPDATA% depending on the Windows OS? I assume I would need to create a public property and then set it using a Custom Action. I have read the Custom Action faq and the How do I install resources based on the Operating System version how-to, but neither answers my question. I created a "Property Set With Formatted" Custom Action, but then realized that is the wrong approach...

I am trying to build a command-line argument that looks like:
"[MY_CUSTOM_PROPERTY]\[Manufacturer]\[ProductName]"

The value of [MY_CUSTOM_PROPERTY] should resolve to either the literal string %APPDATA% or the literal string %LOCALAPPDATA%, as appropriate to the OS version.

Any help or guidance you could provide would be much appreciated.

thanks,
-Todd
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: set java command-line property based on Windows version

Hi Todd,

The "Property Set with Formatted" is the correct approach. What makes you think it is not?
All you need to do is make sure that custom action runs before your product files are installed. Try placing the custom action under InstallInitialize standard action, that should do the trick.

Let me know how it went.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
toddpatt
Posts: 111
Joined: Fri Jan 08, 2010 1:36 am

Re: set java command-line property based on Windows version

Yep, you are correct. I was able to achieve this using two "Property Set With Formatted" Custom Actions:

(1)

Code: Select all

Property Name: MY_CUSTOM_PROP
Formatted Text: %APPDATA%
Expression: VersionNT <= 502
(2)

Code: Select all

Property Name: MY_CUSTOM_PROP
Formatted Text: %LOCALAPPDATA%
Expression: (VersionNT >= 600) OR (VersionNT64 >= 600)
I originally thought "Property Set With Formatted" was the wrong approach because I was confused about how to get the OS version - I completely missed the "Execution Condition" functionality.

As a side-note, I also learned that %APPDATA% on Win2K and WinXP actually maps to the roaming folder (if the user is configured to have a roaming profile). The equivalent non-roaming folder on Win2K and WinXP is "%USERPROFILE%\Local Settings\Application Data". So, my original intent was based on a slight misunderstanding. Anyhow, now I know.

Thanks for your assistance, Gabriel - it's working perfectly!

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

Re: set java command-line property based on Windows version

Thanks, this was useful. I got to thinking about this after observing how Google Chrome installs itself.

Return to “Common Problems”