Re: How to create "user environment variables" programatically for a non-logged on user
- From: "Eugene Gershnik" <gershnik@xxxxxxxxxxx>
- Date: Sat, 3 Sep 2005 22:53:52 -0700
Mel wrote:
> Regd the restriction, well let me explain briefly the problem. My
> installation program embeds a 3rd party software which I install in
> silent mode. Now this 3rd party software installs 2 services. Both
> these services unfortunately use a common environment variable. This
> environment variable has to have 2 different values for the 2
> services to come up at the same time. I thought I would create 2
> users and have that environment variable as a "user environment
> variable", so that I can specify different values for each user. Then
> I would specify each of the 2 services to use the 2 different user
> accounts that I create.
> Logging in the user through LogonUser() api is fine with me.
>
> Is there some other way to solve that problem without creating 2
> users?
Yes there is an easy solution. (A real good one is of course to force the
3rd party vendor to fire the managers of the project that relied on
environment variables on Win32).
The thing to realize is that the process that does the service-ish things
(like StartServiceControlDispatcher etc.) doesn't necessarily have to be the
same process that is started by SCM. All that matters is that some service
starts and in a short period of time some process connects to SCM. Which
gives you a way to insert your own process between SCM and the 3rd party
service.
Write a small console application that will read the needed value from
config file or registry, set the environment variable to this value and then
invoke the service process. Then wait for the service process to die. The
waiting step is important because SCM waits for the process it started and
if it dies pops up the familiar dialog about "the service process terminated
unexpectedly". Make the service entry in registry point to your exe instead
of the original one and you are all set.
I should also mention that if you don't want to change the registry entries
for the service for whatever reason you can also use "Image File Execution
Options" key. Google for this key name to find out what it does.
--
Eugene
http://www.gershnik.com
.
- Follow-Ups:
- References:
- How to create "user environment variables" programatically for a non-logged on user
- From: Mel
- Re: How to create "user environment variables" programatically for a non-logged on user
- From: Eugene Gershnik
- Re: How to create "user environment variables" programatically for a non-logged on user
- From: Mel
- How to create "user environment variables" programatically for a non-logged on user
- Prev by Date: Re: How to create "user environment variables" programatically for a non-logged on user
- Next by Date: Re: Winsocket Error
- Previous by thread: Re: How to create "user environment variables" programatically for a non-logged on user
- Next by thread: Re: How to create "user environment variables" programatically for a non-logged on user
- Index(es):
Relevant Pages
|