Discussion:
"Volatile" Environment variables persist on logoff/login
(too old to reply)
clh
2007-09-10 21:54:09 UTC
Permalink
I'm using the below code in a .vbs to creat a "Volatile" environment
variable. The whole reason I'm doing this is that I DON'T want the value of
this variable to persist when the user logs out or reboots the computer. The
variable is set correctly, and if the computer is completely restarted then
the variable does not persist, but if the user only does a "log off" and then
logs back in, this "Volatile" environment variable is still there.

Everything I've been able to find (which is just a few pieces here and
there) on volatile environment variables says they are NOT supposed to
persist through a log off. So why are they? Or is that by design and the
few things I've found that say that are wrong?

Oh, this is on Windows XP Professional SP2 with all patches up to date.

Thank you.

******************************************
Dim WSHShell
Dim objEnv

Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")

objEnv("TestVar") = "Test Value"

Set objEnv = Nothing
Set WSHShell = Nothing
******************************************
WenYuan Wang [MSFT]
2007-09-11 11:28:23 UTC
Permalink
Hello clh,

According to your description, you meet an issue that "Volatile"
environment variable persists after the user log off.
Please correct me if I misunderstood anything.

I tried to reproduced this issue by the following steps, but failed.

1) I created two vbs files (setValue.vbs and readValue.vbs) on my Windows
XP sp2 machine.
***************** setValue.vbs *************************
Dim WSHShell
Dim objEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")
objEnv("TestVar") = "Test Value"
Set objEnv = Nothing
Set WSHShell = Nothing
******************************************

***************** readValue.vbs *************************
Dim WSHShell
Dim objEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")
MsgBox objEnv("TestVar")
Set objEnv = Nothing
Set WSHShell = Nothing
******************************************

2) Now, I double-click "setValue.vbs" to add "TestVar" into Volatile
environment. Then, I logged off my current account.
3) After log in again, "readValue.vbs" prompt a message box with blank.
It seems "TestVar" has been removed from Volaile environment after I logged
off.

Am I missing something here?
Would you please try the above method and let me the result on your side?
I will perform futher research. thanks.

Have a great day. Please let me know if you have anything unclear. It's my
pleasure to assist you.

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
clh
2007-09-11 18:32:02 UTC
Permalink
You interpret correctly. I just retested this and, go figure, it works now.
The variable is not there after I log off and back in. I know it was
persisting yesterday and can't explain why or what's different today, but
it's not doing it today so it looks like I'm okay. Chalk it up to a fluke I
guess.

Follow-up question though. I have read some other documentation that
Environment variables set in this way during a login script won't persist
past the login script. Is that true? (Haven't had a chance to try it yet.)
They suggest setting environment variables in login scripts in the User or
System environment. I explicitly DON'T want to set them in the User or
System environment because then they will persist through a logoff or reboot.
So I need them to persist beyond the login script, but not through a logoff
or reboot. I don't want them to persist through a logoff or reboot because I
want to make absolutely sure they are set correctly by the login script and
no chance of a user canceling their login script or something happening that
prevents the login script from setting them properly and the variable is
still there with the values from the previous login.

Thank you again!
Post by WenYuan Wang [MSFT]
Hello clh,
According to your description, you meet an issue that "Volatile"
environment variable persists after the user log off.
Please correct me if I misunderstood anything.
I tried to reproduced this issue by the following steps, but failed.
1) I created two vbs files (setValue.vbs and readValue.vbs) on my Windows
XP sp2 machine.
***************** setValue.vbs *************************
Dim WSHShell
Dim objEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")
objEnv("TestVar") = "Test Value"
Set objEnv = Nothing
Set WSHShell = Nothing
******************************************
***************** readValue.vbs *************************
Dim WSHShell
Dim objEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")
MsgBox objEnv("TestVar")
Set objEnv = Nothing
Set WSHShell = Nothing
******************************************
2) Now, I double-click "setValue.vbs" to add "TestVar" into Volatile
environment. Then, I logged off my current account.
3) After log in again, "readValue.vbs" prompt a message box with blank.
It seems "TestVar" has been removed from Volaile environment after I logged
off.
Am I missing something here?
Would you please try the above method and let me the result on your side?
I will perform futher research. thanks.
Have a great day. Please let me know if you have anything unclear. It's my
pleasure to assist you.
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Pegasus (MVP)
2007-09-11 20:18:47 UTC
Permalink
The logon process is a child process same as any other
child process and it obeys the same laws: Child processes
inherit their environmental variables from their parent
process but the parent process never inherits anything
from the child process. You should try this yourself like so:
- Start a Command Prompt and set a variable, e.g. MyName=clh.
- Now launch another command processor from the first one.
- Check %MyName%. It's "clh", of course.
- Set MyName=Jack
- Close the second command processor.
- Check %MyName%. What is it?
Post by clh
You interpret correctly. I just retested this and, go figure, it works now.
The variable is not there after I log off and back in. I know it was
persisting yesterday and can't explain why or what's different today, but
it's not doing it today so it looks like I'm okay. Chalk it up to a fluke I
guess.
Follow-up question though. I have read some other documentation that
Environment variables set in this way during a login script won't persist
past the login script. Is that true? (Haven't had a chance to try it yet.)
They suggest setting environment variables in login scripts in the User or
System environment. I explicitly DON'T want to set them in the User or
System environment because then they will persist through a logoff or reboot.
So I need them to persist beyond the login script, but not through a logoff
or reboot. I don't want them to persist through a logoff or reboot because I
want to make absolutely sure they are set correctly by the login script and
no chance of a user canceling their login script or something happening that
prevents the login script from setting them properly and the variable is
still there with the values from the previous login.
Thank you again!
Post by WenYuan Wang [MSFT]
Hello clh,
According to your description, you meet an issue that "Volatile"
environment variable persists after the user log off.
Please correct me if I misunderstood anything.
I tried to reproduced this issue by the following steps, but failed.
1) I created two vbs files (setValue.vbs and readValue.vbs) on my Windows
XP sp2 machine.
***************** setValue.vbs *************************
Dim WSHShell
Dim objEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")
objEnv("TestVar") = "Test Value"
Set objEnv = Nothing
Set WSHShell = Nothing
******************************************
***************** readValue.vbs *************************
Dim WSHShell
Dim objEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")
MsgBox objEnv("TestVar")
Set objEnv = Nothing
Set WSHShell = Nothing
******************************************
2) Now, I double-click "setValue.vbs" to add "TestVar" into Volatile
environment. Then, I logged off my current account.
3) After log in again, "readValue.vbs" prompt a message box with blank.
It seems "TestVar" has been removed from Volaile environment after I logged
off.
Am I missing something here?
Would you please try the above method and let me the result on your side?
I will perform futher research. thanks.
Have a great day. Please let me know if you have anything unclear. It's my
pleasure to assist you.
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
clh
2007-09-11 21:02:06 UTC
Permalink
I understand what you're saying and that is true when strictly talking about
Command Prompts. But what I'm doing here is using a VBS to explicitly set a
variable in the "Volatile" environment. When I run the VBS manually, the
variable DOES appear in the master environment. I.e., I can open a new
command prompt and type SET and the variable DOES appear, or I can run
another VBS that reads the environment variable and it does successfully read
the variable. (The variable does not appear in any command prompts or
processes that were already open before I run the initial .VBS and I expect
that and understand why.) So if it works when I run the VBS manually, why
would it not work when I implement that VBS as a login script? But I've read
that it won't.
Post by Pegasus (MVP)
The logon process is a child process same as any other
child process and it obeys the same laws: Child processes
inherit their environmental variables from their parent
process but the parent process never inherits anything
- Start a Command Prompt and set a variable, e.g. MyName=clh.
- Now launch another command processor from the first one.
- Check %MyName%. It's "clh", of course.
- Set MyName=Jack
- Close the second command processor.
- Check %MyName%. What is it?
Pegasus (MVP)
2007-09-11 21:06:47 UTC
Permalink
WenYuan dealt with this aspect of your question and I see
no need to repeat his tests. You should by now have plenty
of background information to run your own tests.
Post by clh
I understand what you're saying and that is true when strictly talking about
Command Prompts. But what I'm doing here is using a VBS to explicitly set a
variable in the "Volatile" environment. When I run the VBS manually, the
variable DOES appear in the master environment. I.e., I can open a new
command prompt and type SET and the variable DOES appear, or I can run
another VBS that reads the environment variable and it does successfully read
the variable. (The variable does not appear in any command prompts or
processes that were already open before I run the initial .VBS and I expect
that and understand why.) So if it works when I run the VBS manually, why
would it not work when I implement that VBS as a login script? But I've read
that it won't.
Post by Pegasus (MVP)
The logon process is a child process same as any other
child process and it obeys the same laws: Child processes
inherit their environmental variables from their parent
process but the parent process never inherits anything
- Start a Command Prompt and set a variable, e.g. MyName=clh.
- Now launch another command processor from the first one.
- Check %MyName%. It's "clh", of course.
- Set MyName=Jack
- Close the second command processor.
- Check %MyName%. What is it?
WenYuan Wang [MSFT]
2007-09-12 11:38:18 UTC
Permalink
Hello clh,
Thanks for your reply.
Follow-up question though. I have read some other documentation that
Environment variables set in this way during a login script won't persist
past the login script. Is that true?

In order to test this situation, I copied the "setValue.vbs" to
C:\WINDOWS\System32\GroupPolicy\User\Scripts\Logon, and added it into
"group policy"|"User Configuration"|"Windows Settings"|"Script Logon and
Logout".
I logged off current account. After I logged in again, the
objEnv("TestVar") still persists.
Environment variables still persists, even if variables set during a login
script.

By the way, to make sure the Value has been removed after user logged off,
I have an idea that we may write a "removeValue.vbs" to remove the
Environment Variables, and set it as Logout script in Group Plocy.
Thereby, each time the user logs off, the value will be deleted.

Hope this helps. Please let me know if you have any more concern. We are
glad to assist you.
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

***************** removeValue.vbs *************************
Dim WSHShell
Dim objEnv
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WSHShell.Environment("Volatile")
objEnv.Remove("TestVar")
Set objEnv = Nothing
Set WSHShell = Nothing
******************************************
clh
2007-09-28 17:16:01 UTC
Permalink
Post by WenYuan Wang [MSFT]
Hello clh,
Thanks for your reply.
Follow-up question though. I have read some other documentation that
Environment variables set in this way during a login script won't persist
past the login script. Is that true?
We finally got it set up so I could test this (I was waiting on 3 other
people to get things done). The variables do persist after the login script,
so I'm good there.
Post by WenYuan Wang [MSFT]
By the way, to make sure the Value has been removed after user logged off,
I have an idea that we may write a "removeValue.vbs" to remove the
Environment Variables, and set it as Logout script in Group Plocy.
Thereby, each time the user logs off, the value will be deleted.
I am back now though to where the variables persist after a logoff and logon
(but not across a full reboot). Most of the time they do persist through a
logoff and logon, but sometimes they won't. I can't figure out anything
specific as to the PC when they do and don't. To test this most recently I
did the following. Logged in and the login script set the variables as
expected. I logged off. I disconnected the LAN cable to be sure that when I
logged back in (using cached credentials) the login script couldn't run
again. Logged back in, the script did not run, but the "volatile"
environment variables were still there.

The logoff script might be an option but I doubt I'll be able to get our
Corporate systems admin people to go for it. Unfortunately I don't have any
direct control over the AD systems.

So I'm still back to, if anybody has any ideas on why "volatile" environment
variables persist after a logoff and logon, when all the documentation I've
read says they're not supposed to, I'd appreciate any ideas on things to
check.

Thanks again!
WenYuan Wang [MSFT]
2007-10-03 03:32:53 UTC
Permalink
Hello CLH

Sorry for delay, I'm on vacation yesterday.

We need to perform more research on this issue . We will reply here as soon
as possible.
If you have any more concerns on it, please feel free to post here.

Thanks for your understanding!
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
clh
2007-10-03 13:58:01 UTC
Permalink
Post by WenYuan Wang [MSFT]
Hello CLH
Sorry for delay, I'm on vacation yesterday.
We need to perform more research on this issue . We will reply here as soon
as possible.
If you have any more concerns on it, please feel free to post here.
No problem. Thanks very much! I greatly appreciate that you are taking
time to look into it.
WenYuan Wang [MSFT]
2007-10-04 08:27:04 UTC
Permalink
Hello clh,
Thanks for your waiting.

I have reproduced this issue. Sometimes, the "Volatile" Environment
variables persist on logoff.
The issue seems strangle.

Is it possible for you to send me an email? I need some more detailed
information for further analyze.
My alias is v-***@online.microsoft.com (please remove "online.").

Please feel free to let me know if you have any more concern. We are glad
to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WenYuan Wang [MSFT]
2007-09-17 06:58:56 UTC
Permalink
Hello clh,

This is Wen Yuan again. I haven't heard from you a couple of days.
Is there anything we can help with?
Please let us know if you need any further assistance . It's my pleasure to
assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Loading...