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!

Ruben
Posts: 57
Joined: Fri Apr 10, 2015 2:35 pm

Can a service access new environment variables ?

Our installer finally starts a service.
To startup correctly, this service needs an environment variable created in the same installation.

Can that work reliably ?


Thank you.
Ruben

I've got some doubt after I read http://www.advancedinstaller.com/forums ... .php?t=778, althought it's rather old.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Can a service access new environment variables ?

Hello Ruben,

I'm afraid this is not possible. On Windows systems the environment variable list is refreshed just after the process, which update the variable list, ends. So, when creating an environment variable from the installation process, the variable will be available on the system only after the installation process ends.

As a workaround solution you can try to develop your own custom action to create the environment variable and add the custom action as asynchronous action. Just uncheck its "Wait for the custom action to finish before proceeding" and "Wait for return code at the end of the sequence" execution options. Also, the custom action should be scheduled before "Install Execution Stage -> Add Resources" action group. You can test this and see if it works.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Ruben
Posts: 57
Joined: Fri Apr 10, 2015 2:35 pm

Re: Can a service access new environment variables ?

HI Daniel, I'm in doubt with your idea. I guess we can't predict for sure when an asynchronous action has finished.
Are you sure this can be 100% reliable ?

Testing won't help. My current, questionable solution (Set the variable in Installer, start a service that uses it) also works well in my tests !

We need a waterproof solution. Not only must it stand my tests, but also work in theory ;-)

Best regards,
Ruben
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Can a service access new environment variables ?

Hello Ruben,
HI Daniel, I'm in doubt with your idea. I guess we can't predict for sure when an asynchronous action has finished.
Are you sure this can be 100% reliable ?
No, unfortunately this is not foolproof. This is because the installation process cannot check when an asynchronous action ends.
Testing won't help. My current, questionable solution (Set the variable in Installer, start a service that uses it) also works well in my tests !
We need a waterproof solution. Not only must it stand my tests, but also work in theory ;-)
I'm afraid I'm not aware of such 100% reliable solution. However, it is curious that your solution works. From what I know the environment variable list is loaded when a process start, but maybe this don't apply to services also. Maybe the service start operation is not related at all with the parent installation process and thus it can access successfully the created environment variable. Our service install and start operations are solely using the standard Windows Installer support through "ServiceInstall" and "ServiceControl" tables.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Ruben
Posts: 57
Joined: Fri Apr 10, 2015 2:35 pm

Re: Can a service access new environment variables ?

For all who want to know ...

I didn't dare to use my first solution although it worked.
Our scenario was:
- start a java service
- we use JSL (Author: Michael Roeschter) to run the java app as a service
- JSL is configured to find the Java Machine by a environment variable.
We provide two installer packages (one with Java bundled, one without). That's why we use an environment variable. It points to our bundled Java either, or to another custom Java.

What's the problem now?
1. For the non-Java package, someone else must provide the environment variable prematurely => Not our problem :-)

2. For the package with Java bundled, the problem comes up.
First solution:
- The environment variable pointing to Java was set by the Installer, and pointed to the bundled Java.
- The service was configured to use this freshly created variable. And it started successfully (but we don't trust.)

What we do now:
The package with Java bundled does configure the JSL without an environment variable. The Java path is hard coded in the configuration.

There are two disadvantages: the user cannot quickly change the JVM by modifing the environment variable. Further, our installer project is slightly more complicated.
Both are acceptable and we are done.


Nonetheless, I'll stay tuned for updates and further advices.

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

Re: Can a service access new environment variables ?

Hello Ruben,

Thank you for your feedback.

I'm afraid I'm not aware of any other solutions you can always reliably use.

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

Return to “Building Installers”