Windows Service doesn't pickup new System Variables?

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 00:29:13


Hi all,
I wish I post the message at the right place.

The problem I am having is, I programmed a service, and:

1. When the Service started, it pickup the environment settings.
2. Then I modified a System Variable, say the Path.
3. I restarted the Service, hoping that it will pickup the new
System Variable (Path)
4. But it didn't.
5. Sometimes it did though! Sometimes I had to reboot the PC to get it
to work. And sometimes, not even a reboot can fix the problem.

Thanks.

Best,
Jeffrey
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 00:46:56

BTW: When I use Command Prompt to execute a "set" command, it does give me
the new variable value. So I figiure that Service is special? What can I do
to work around this problem? Thanks.

 
 
 

Windows Service doesn't pickup new System Variables?

Post by Ivan Brugi » Wed, 21 Jul 2004 00:52:13

Try this article for an overview of what should be going on

http://www.yqcomputer.com/

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.yqcomputer.com/
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 01:38:25

Thanks.

But the article only tells you how to notify other applications by sending
out WM_SETTINGCHANGE.
It doesn't tell us how to perform an update when we get this message.

Plus, the article says we have to logoff and on to reflect the change of
variable, which is not the case: I
don't have to logoff / on to get the new variable from my DOS Prompt.



rights.
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Ivan Brugi » Wed, 21 Jul 2004 01:40:24

Can you re-read the SessionManager key ?

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.yqcomputer.com/
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 02:12:02

Yes, it stores the right value there.

The funny thing is, I managed to build two services. (With very simple code:
Just print out the System Variables). Then I started to test them by
modifying
the System Variable. Now one service got a old value, another got an even
older value, and the registry told me I have a third value.

I guess the service caches Env???



rights.


sending


at


it
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 02:48:52

Just have a thought, maybe the SCM doesn't

update the environment changes sometimes?!

This problem happens not only in my PC, but

in two different PCs.



Thanks.
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Raimun » Wed, 21 Jul 2004 03:07:21

very strange??

Normaly, every service ist started, say spawned, from services.exe.
The environment, say all machine variables, is inherited from this
"father"-process. If your self-written service-process doesn't handle
"WININICHANGES", that is default behavior, the only way to change
the environment for that proces is to restart services.exe. Services.exe
is restartet during machine reboot.
Any change you made, maybe written into the registry, but this
reources is'nt read by the process services.exe again and again.

Any environment you see, e.g. in a dos cmd-box, is a mixture
of the values in the registry: machine-values and user-values.
Those values are normaly inherited or rebuild during process-creation.

Hope it's helpfull.
Raimund



"Jeffrey Meng" < XXXX@XXXXX.COM > schrieb im Newsbeitrag
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 03:19:07

Thanks a lot.

I understand if I don't reboot (restart Services.exe), the changes
might not be reflected.

But I am really confused that sometimes even when I reboot the whole
PC, my service still got the old value, like it's cached somewhere!

- Jeffrey
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 03:20:22

And where do I handle WININICHANGES? I can't find this macro or whatsoever
in MSDN.

Thanks - Jeffrey
 
 
 

Windows Service doesn't pickup new System Variables?

Post by Jeffrey Me » Wed, 21 Jul 2004 04:07:30

There is one thing I can work around it.

Each time I need the Env settings, I load it from the registry and
update the Env Block.

Sounds good?