system environment not inherited by some cmd windows

T

Tom Del Rosso

Using XP Pro SP3, if I set a variable with setx, then open a new cmd window
and type set, the variable is shown.

But if I open a new cmd window by right-clicking a folder and selecting
"command prompt", the window does not inherit system variables set earlier
in the same session.

My "command prompt" folder option is set up with this reg file:


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\OpenCMDWindow]
@="Command Prompt"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCMDWindow\Command]
@="C:\WINDOWS\system32\cmd.exe"

[HKEY_CLASSES_ROOT\Drive\shell\OpenCMDWindow]
@="Command Prompt"
[HKEY_CLASSES_ROOT\Drive\shell\OpenCMDWindow\Command]
@="C:\WINDOWS\system32\cmd.exe"

--
 
T

Tom Del Rosso

@="C:\WINDOWS\system32\cmd.exe"

@="C:\WINDOWS\system32\cmd.exe"

BTW, those lines do have double \\ in the actual reg file. An editing error
got into the post.
 
I

I'm_HERE

REGEDIT4

[HKEY_CLASSES_ROOT\Directory\shell\OpCmdWin]
@=" ======== Command Prompt ========"

[HKEY_CLASSES_ROOT\Directory\shell\OpCmdWin\command]
@="D:\\windows\\SYSTEM32\\cmd.exe /T:17 /k \"Mode Con: Cols=100
Lines=40&cd \"%1\"\""

[HKEY_CLASSES_ROOT\Drive\shell\OpCmdWin]
@=" ======== Command Prompt ========"

[HKEY_CLASSES_ROOT\Drive\shell\OpCmdWin\command]
@="D:\\windows\\SYSTEM32\\cmd.exe /T:17 /k \"Mode Con: Cols=100
Lines=40&cd \"%1\"\""
 
D

Dave Patrick

Do you find them here?

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
 
T

Tom Del Rosso

Dave said:
Do you find them here?

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Yes, setx worked normally and changed the registry values.

Also, editing the system environment in system properties behaves the same
as setx. After doing that I get the same results from new command windows
as with setx. The normal command window inherits the changes but windows
opened with "command window here" have the environment the system booted
with.

So the issue is that cmd windows are different when opened that way.

My best guess is that cmd windows opened that way inherit their environment
from the explorer window where I right-clicked the folder. On a hunch I
just confirmed this by turning off "launch folder windows in a separate
process". Now they inherit the latest environment. But that doesn't really
explain it. I would think that if each one is a new process then it should
inherit the latest changes.

I want folder windows in a new process for stability and for the ability to
open folders as a different user, but I expect there's no way around this.

--
 
S

Sjouke Burry

Tom said:
Yes, setx worked normally and changed the registry values.

Also, editing the system environment in system properties behaves the same
as setx. After doing that I get the same results from new command windows
as with setx. The normal command window inherits the changes but windows
opened with "command window here" have the environment the system booted
with.

So the issue is that cmd windows are different when opened that way.

My best guess is that cmd windows opened that way inherit their environment
from the explorer window where I right-clicked the folder. On a hunch I
just confirmed this by turning off "launch folder windows in a separate
process". Now they inherit the latest environment. But that doesn't really
explain it. I would think that if each one is a new process then it should
inherit the latest changes.

I want folder windows in a new process for stability and for the ability to
open folders as a different user, but I expect there's no way around this.
Why dont you use a batch file to save and/or set the variables you want?
For saving, use a batch containing

set var1>c:\temp\restore.bat
set var2>>c:\temp\restore.bat
...
...
...
...
...
set varn>>c:\temp\restore.bat

and maybe a line with
path>>c:\temp\restore.bat


Then when you want to get the right env vars,
execute c:\temp\restore.bat

all that assumes the presence of directory c:\temp of course .
 
T

Tom Del Rosso

Sjouke said:
Why dont you use a batch file to save and/or set the variables you
want? For saving, use a batch containing

set var1>c:\temp\restore.bat
set var2>>c:\temp\restore.bat

Some variables have to be in the non-volatile system environment.

--
 
D

Dave Patrick

That does seem strange and you're probably right about how it happens. I
wonder if someone here has seen that or knows about it.

x-posted to: microsoft.public.win2000.cmdprompt.admin


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect


Tom Del Rosso said:
Yes, setx worked normally and changed the registry values.

Also, editing the system environment in system properties behaves the same
as setx. After doing that I get the same results from new command windows
as with setx. The normal command window inherits the changes but windows
opened with "command window here" have the environment the system booted
with.

So the issue is that cmd windows are different when opened that way.

My best guess is that cmd windows opened that way inherit their
environment from the explorer window where I right-clicked the folder. On
a hunch I just confirmed this by turning off "launch folder windows in a
separate process". Now they inherit the latest environment. But that
doesn't really explain it. I would think that if each one is a new
process then it should inherit the latest changes.

I want folder windows in a new process for stability and for the ability
to open folders as a different user, but I expect there's no way around
this.

--


Dave said:
Do you find them here?

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\OpenCMDWindow]
@="Command Prompt"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCMDWindow\Command]
@="C:\WINDOWS\system32\cmd.exe"
[HKEY_CLASSES_ROOT\Drive\shell\OpenCMDWindow]
@="Command Prompt"
[HKEY_CLASSES_ROOT\Drive\shell\OpenCMDWindow\Command]
@="C:\WINDOWS\system32\cmd.exe"
 
T

Tim Meddick

I can confirm that it happens because of Explorer being set to launch "as a
separate process". In this case, it does not "inherit" env vars because
explorer only updates it's environment with every new instance of explorer.
i.e. set an environment variable in a command window using setx and if you
IMMEADIATLY open a NEW explorer window and right-click on a folder and
select 'Command Prompt' it WILL display the new variable. However, if the
instance of explorer was ALREADY OPEN at the same time as the command
windows set the new variable, then it WILL NOT show the new variable because
that Explorer was isolated by being an 'instance' separate and it's
environment is also separate. A new instance of explorer carries the
updated Window's environment. However, ALL OPEN EXPLORER INSTACES HAVE TO
CLOSE before a 'new' instance will uptake the new set of variables.


==


Cheers, Tim Meddick, Peckham, London.


Dave Patrick said:
That does seem strange and you're probably right about how it happens. I
wonder if someone here has seen that or knows about it.

x-posted to: microsoft.public.win2000.cmdprompt.admin


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect


Tom Del Rosso said:
Yes, setx worked normally and changed the registry values.

Also, editing the system environment in system properties behaves the
same as setx. After doing that I get the same results from new command
windows as with setx. The normal command window inherits the changes but
windows opened with "command window here" have the environment the system
booted with.

So the issue is that cmd windows are different when opened that way.

My best guess is that cmd windows opened that way inherit their
environment from the explorer window where I right-clicked the folder.
On a hunch I just confirmed this by turning off "launch folder windows in
a separate process". Now they inherit the latest environment. But that
doesn't really explain it. I would think that if each one is a new
process then it should inherit the latest changes.

I want folder windows in a new process for stability and for the ability
to open folders as a different user, but I expect there's no way around
this.

--


Dave said:
Do you find them here?

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
:
Using XP Pro SP3, if I set a variable with setx, then open a new cmd
window and type set, the variable is shown.
But if I open a new cmd window by right-clicking a folder and selecting
"command prompt", the window does not inherit system variables set
earlier in the same session.
My "command prompt" folder option is set up with this reg file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\OpenCMDWindow]
@="Command Prompt"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCMDWindow\Command]
@="C:\WINDOWS\system32\cmd.exe"
[HKEY_CLASSES_ROOT\Drive\shell\OpenCMDWindow]
@="Command Prompt"
[HKEY_CLASSES_ROOT\Drive\shell\OpenCMDWindow\Command]
@="C:\WINDOWS\system32\cmd.exe"
 
T

Tim Meddick

No Problem. (although there is, with explorer)


==


Cheers, Tim Meddick, Peckham, London.


Dave Patrick said:
Thank you Tim.


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect


Tim Meddick said:
I can confirm that it happens because of Explorer being set to launch "as
a separate process". In this case, it does not "inherit" env vars because
explorer only updates it's environment with every new instance of
explorer. i.e. set an environment variable in a command window using setx
and if you IMMEADIATLY open a NEW explorer window and right-click on a
folder and select 'Command Prompt' it WILL display the new variable.
However, if the instance of explorer was ALREADY OPEN at the same time as
the command windows set the new variable, then it WILL NOT show the new
variable because that Explorer was isolated by being an 'instance'
separate and it's environment is also separate. A new instance of
explorer carries the updated Window's environment. However, ALL OPEN
EXPLORER INSTACES HAVE TO CLOSE before a 'new' instance will uptake the
new set of variables.


==


Cheers, Tim Meddick, Peckham, London.
 
T

Tom Del Rosso

Tim said:
I can confirm that it happens because of Explorer being set to launch
"as a separate process". In this case, it does not "inherit" env
vars because explorer only updates it's environment with every new
instance of explorer. i.e. set an environment variable in a command
window using setx and if you IMMEADIATLY open a NEW explorer window
and right-click on a folder and select 'Command Prompt' it WILL
display the new variable. However, if the instance of explorer was
ALREADY OPEN at the same time as the command windows set the new
variable, then it WILL NOT show the new variable because that
Explorer was isolated by being an 'instance' separate and it's
environment is also separate. A new instance of explorer carries the
updated Window's environment. However, ALL OPEN EXPLORER INSTACES
HAVE TO CLOSE before a 'new' instance will uptake the new set of
variables.

Thanks.
 
G

Gilles LAURENT [MVP]

"Tim Meddick" <[email protected]> a écrit dans le message de

Hi Tim,

| I can confirm that it happens because of Explorer being set to launch
| "as a separate process". In this case, it does not "inherit" env
| vars because explorer only updates it's environment with every new
| instance of explorer. i.e. set an environment variable in a command
| window using setx and if you IMMEADIATLY open a NEW explorer window
| and right-click on a folder and select 'Command Prompt' it WILL
| display the new variable. However, if the instance of explorer was
| ALREADY OPEN at the same time as the command windows set the new
| variable, then it WILL NOT show the new variable because that
| Explorer was isolated by being an 'instance' separate and it's
| environment is also separate. A new instance of explorer carries the
| updated Window's environment. However, ALL OPEN EXPLORER INSTACES
| HAVE TO CLOSE before a 'new' instance will uptake the new set of
| variables.

You're right and it's exactly to avoid this issue that I wrote the tool
DynSetEnv :
http://glsft.free.fr/index.php?option=com_content&task=view&id=67&Itemid=28

To make a variable available in current and new instances of explorer :
\> DynSetEnv -name testvar -value test -recurse

Hope this helps.
 
M

Matthias Tacke

M

Matthias Tacke

Gilles said:
You're right and it's exactly to avoid this issue that I wrote the tool
DynSetEnv :
http://glsft.free.fr/index.php?option=com_content&task=view&id=67&Itemid=28

To make a variable available in current and new instances of explorer :
\> DynSetEnv -name testvar -value test -recurse

Hope this helps.
Hello Giles,
just discovered your console WSH Shell - looks very interesting,
mais je ne pas parlez Francais, seule un petit peux ;-)

Are there any reviews in English or German?

Regards
 
G

Gilles LAURENT [MVP]

"Matthias Tacke" <[email protected]> a écrit dans le message de
| Hello Giles,

Hi Matthias,

| just discovered your console WSH Shell - looks very interesting,
| mais je ne pas parlez Francais, seule un petit peux ;-)
| Are there any reviews in English or German?

No translation of the tutorials is available for the moment but I think
the commands can help. However the integrated help system is available
in english. To discover builtin commands, functions, subs and
properties, just type _gethelp at the command prompt. To run a
script-block interactively, you have to use a backtick at the first line
and use an empty line to close the script block. For example :
WSH D:\Test> For i=0 To 10 `1 2 3 4 5 6 7 8 9 10 11
WSH D:\Test>

WSH Shell Console :
http://glsft.free.fr/index.php?option=com_content&task=category&sectionid=4&id=19&Itemid=28

Note: The tutorials are available at the end of the page. You have to
begin to read the last one.

Best regards.
 
T

Tim Meddick

Gilles,
I live for programs like this, bring back DOS I say! But, failing
that, I can live inside the 'Command Environment' if I've got tools like
this one. (Very reminiscent of MS's WinSet.exe - Set Windows Master
Variables for Win98)
So thanks allot for that one!

==


Cheers, Tim Meddick, Peckham, London.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top