J
JC
I've noticed that starting up a new cmd.exe prompt no longer displays the current
environmental variables. Where does cmd.exe get it's ev's from? Is there an API
to call in order to force a Windows cmd.exe prompt to read System EVs from the
registry?
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment
HKLM\SYSTEM\ControlSet002\Control\Session Manager\Environment
All three of these keys display the same values. Yet, when I start up a cmd.exe
prompt, Windows reads OLD values that no longer exist anywhere inside the
registry. The keys were changed last week... and the keys display the proper
values, but a new cmd.exe prompt displays OLD values.
The OS tested is XP Professional SP2.
I've also tried two different cmd.exe prompts, one in the system32 folder and
one in another folder (a copy of that, not a .lnk to it).
I discovered a way to correct it. But something may be wrong, because it
should have taken effect the first time I changed it (I think, or I need to make an
extra API call to force the changes over to a cmd.exe prompt).
1) Right-click upon My Computer, click upon the Advanced tab, click upon
the Environmental Variables button.
2) Click upon the EV that needs to get changed.
3) Change the EV to the appropriate path (I simply added "\." to the path that
already exists there).
4) Click OK to close the Environmental Variables dialog.
5) Click OK to close the System Properties dialog.
6) Open a cmd.exe prompt and take a look at the changed EV.
That corrected it, but it should have been corrected previously, I think. I'm thinking
along the lines that there's a bug when closing one of the dialogs, where Windows
changes the keys in the registry, but somewhere caches the old information and
fails to reflect the changes when opening a new cmd.exe prompt... more testing...
OK. To duplicate the problem and recreate the issue:
1) Open the registry editor.
2) Change any environmental key in
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
3) Go through the steps listed above to verify the key was changed without changing
anything there.
4) Open a cmd.exe prompt.
5) Check the EV you just changed in the registry. You will see that the registry either
did NOT get updated or that the cmd.exe prompt did NOT read from the registry. And
what I see, is that right-clicking upon My Computer does REREAD from the registry,
while starting up a new cmd.exe prompt does not. Even if you CLOSE all existing cmd
prompts and re-open a new prompt, the registry is NOT read.
The steps above indicate:
1) An API call exists to push the changes through so newly opened cmd prompts get
the changes and reflect the changes.
2) The EV's tested above were System Variables as opposed to User Variables. I
did not test User Variables, and currently think that the problem exists when doing
similar changes to User Variables in the registry.
3) It's only a cmd prompt issue, as reading changed keys from the registry reflects the
changes.
I believe this problem also exists in other programming languages, not only VB. So what
happens is if you call a .bat or .cmd script from an application after making changes to
System EVs in the registry (possibly User EVs as well), the .bat or .cmd may NOT reflect
the changed EVs (I have not fully tested this as I recently recognized the problem and I'm
just posting this if anyone wants to check, I'm anticipating other possible problems at the
moment - too late for me to get into this tonight).
NOTE: It's ONLY in starting a new cmd prompt that I see the problem where the EV that
gets displayed in the cmd prompt reflects an OLD EV that was changed through via a
call to the registry.
Hope the information here helps others correct EV problems with the cmd.exe prompt.
And one last thing, can anyone else duplicate the problem with other Microsoft OS's?
environmental variables. Where does cmd.exe get it's ev's from? Is there an API
to call in order to force a Windows cmd.exe prompt to read System EVs from the
registry?
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment
HKLM\SYSTEM\ControlSet002\Control\Session Manager\Environment
All three of these keys display the same values. Yet, when I start up a cmd.exe
prompt, Windows reads OLD values that no longer exist anywhere inside the
registry. The keys were changed last week... and the keys display the proper
values, but a new cmd.exe prompt displays OLD values.
The OS tested is XP Professional SP2.
I've also tried two different cmd.exe prompts, one in the system32 folder and
one in another folder (a copy of that, not a .lnk to it).
I discovered a way to correct it. But something may be wrong, because it
should have taken effect the first time I changed it (I think, or I need to make an
extra API call to force the changes over to a cmd.exe prompt).
1) Right-click upon My Computer, click upon the Advanced tab, click upon
the Environmental Variables button.
2) Click upon the EV that needs to get changed.
3) Change the EV to the appropriate path (I simply added "\." to the path that
already exists there).
4) Click OK to close the Environmental Variables dialog.
5) Click OK to close the System Properties dialog.
6) Open a cmd.exe prompt and take a look at the changed EV.
That corrected it, but it should have been corrected previously, I think. I'm thinking
along the lines that there's a bug when closing one of the dialogs, where Windows
changes the keys in the registry, but somewhere caches the old information and
fails to reflect the changes when opening a new cmd.exe prompt... more testing...
OK. To duplicate the problem and recreate the issue:
1) Open the registry editor.
2) Change any environmental key in
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
3) Go through the steps listed above to verify the key was changed without changing
anything there.
4) Open a cmd.exe prompt.
5) Check the EV you just changed in the registry. You will see that the registry either
did NOT get updated or that the cmd.exe prompt did NOT read from the registry. And
what I see, is that right-clicking upon My Computer does REREAD from the registry,
while starting up a new cmd.exe prompt does not. Even if you CLOSE all existing cmd
prompts and re-open a new prompt, the registry is NOT read.
The steps above indicate:
1) An API call exists to push the changes through so newly opened cmd prompts get
the changes and reflect the changes.
2) The EV's tested above were System Variables as opposed to User Variables. I
did not test User Variables, and currently think that the problem exists when doing
similar changes to User Variables in the registry.
3) It's only a cmd prompt issue, as reading changed keys from the registry reflects the
changes.
I believe this problem also exists in other programming languages, not only VB. So what
happens is if you call a .bat or .cmd script from an application after making changes to
System EVs in the registry (possibly User EVs as well), the .bat or .cmd may NOT reflect
the changed EVs (I have not fully tested this as I recently recognized the problem and I'm
just posting this if anyone wants to check, I'm anticipating other possible problems at the
moment - too late for me to get into this tonight).
NOTE: It's ONLY in starting a new cmd prompt that I see the problem where the EV that
gets displayed in the cmd prompt reflects an OLD EV that was changed through via a
call to the registry.
Hope the information here helps others correct EV problems with the cmd.exe prompt.
And one last thing, can anyone else duplicate the problem with other Microsoft OS's?