Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Environment vars

0 views
Skip to first unread message

Marcus Hammer

unread,
Sep 25, 1997, 3:00:00 AM9/25/97
to


HI,

I wrote a C - Program for NT 4. I read a environment var with getenv and
want to set it for the parent process wie _putenv, but
the envvar I is only visible to the current process, not for the parent
process. How can I change environment vars for the parent process under
Windows NT 4???

cu MC


dr john halewood

unread,
Sep 26, 1997, 3:00:00 AM9/26/97
to

On Thu, 25 Sep 1997 18:50:00 +0200, "Marcus Hammer"
<ham...@alpha.fh-furtwangen.de> wibbled:

You can set environment variables for NT by setting the registry
entries in
HKEY_LOCAL_MACHINE\CurrentControlSet\Control\Session
Manager\Environment

but I don't know if they're inherited immediately on being set or if
you have to wait for the process to exit/system to reboot: certainly a
dos session doesn't pick these up until the system's rebooted. well,
it doesn't on my machine anyway.

There's probably another way around this but that's all i can think of
at the moment....

cheers,

john

Leopold Faschalek

unread,
Sep 26, 1997, 3:00:00 AM9/26/97
to

Sorry you can't do this.

Marcus Hammer <ham...@alpha.fh-furtwangen.de> wrote in article
<#ifN$Ndy8G...@uppssnewspub05.moswest.msn.net>...
>
>
> HI,


>
> I wrote a C - Program for NT 4. I read a environment var with getenv and
> want to set it for the parent process wie _putenv, but
> the envvar I is only visible to the current process, not for the parent
> process. How can I change environment vars for the parent process under
> Windows NT 4???
>

> cu MC
>
>
>
>

David A. Hoatson

unread,
Sep 29, 1997, 3:00:00 AM9/29/97
to

>Sorry you can't do this.

Of course you can. Just write it into the registry under:

HKEY_LOCAL_MACHINE
SYSTEM
CurrentControlSet
Session Manager
Environment

This will add another envrionment variable to the global set.

David A. Hoatson
Spectrum Productions

Return address mangled to avoid junk mail.


Marcus Hammer

unread,
Sep 29, 1997, 3:00:00 AM9/29/97
to


>Sorry you can't do this.

How can I realize an Unix 'export' of env. vars under the NT - console. When
I install VC++ or any other MS - Product they also set global envvars.

cu MC

ham...@alpha.fh-furtwangen.de

Vincent Fatica

unread,
Sep 30, 1997, 3:00:00 AM9/30/97
to

On Mon, 29 Sep 1997 22:53:45 +0200, "Marcus Hammer"
<ham...@alpha.fh-furtwangen.de> wrote:

>How can I realize an Unix 'export' of env. vars under the NT - console. When
>I install VC++ or any other MS - Product they also set global envvars.

There is no need for "export". Variables set with "set" are
immediately available to commands in the current shell and are passed
to subshells. Just as in UNIX, there is no way to alter the
environment of a parent shell ("export" does not do this). Global
variables can be set with SETX.EXE (ResKit) or my SETENV.EXE (see my
homepage). These programs alter the "user" and "machine" environments
stored in the registry keys:

"HKEY_CURRENT_USER\Environment" and
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment"

Explorer is made aware of such global changes and will give the new
environment to NEWLY started programs. Programs already running will
not update their environments (unless they have been designed to
respond to "SendMessageTimeout ... WM_SETTINGCHANGE ... Environment"
by updating their environments). As far as I know, Explorer is the
only program designed to respond to this message.

- Vince

___
Vincent Fatica
Syracuse University Mathematics
vefa...@syr.edu
http://barnyard.syr.edu/~vefatica/

Antonio E. Scuri

unread,
Sep 30, 1997, 3:00:00 AM9/30/97
to

How can I programatically do this in Windows 95?

I know I can because there is a program called WINSET.EXE, in the
Windows 95 Distribution CD-ROM that sets an environment variable in its
global environment, and it works...

Thanks in Advance,

Antonio Scuri

Vincent Fatica

unread,
Oct 7, 1997, 3:00:00 AM10/7/97
to

On Mon, 29 Sep 1997 23:30:45 +0200, "David A. Hoatson"
<dhoatson_r...@earthlink.net> wrote:

>>Sorry you can't do this. (L. Faschalek)


>
>Of course you can. Just write it into the registry under:
>
>HKEY_LOCAL_MACHINE
> SYSTEM
> CurrentControlSet
> Session Manager
> Environment
>
>This will add another envrionment variable to the global set.

... but not to the environment of any running CMD (likewise for most
other programs). The original question (M. Hammer) was "How can I
change environment vars for the parent process under Windows NT 4???".
In general, you can't (unless the parent in question is explorer).

Further, just writing it to the registry is not sufficient to make
even explorer aware of it. You must "SendMessageTimeout ...
WM_SETTINGCHANGE ... Environment" (or something similar, see the KB's
Q104011) to make explorer update its environment. Very few programs
are designed to update their own environments when global settings are
changed.

0 new messages