Hi, I have a script that set environment variables in the following way :

Set WshEnv = WshShell.Environment("USER")

WshEnv("Appvar1") = xyz

This works ok, and when going to the User's Environment variables section on
the computer, all the custom variables are there, but the problem is they
don't seem to be already loaded into memory or the value doesn't seems to be
loaded by the OS...

Here is why I think this : If I go to start/run, and type %Appvar1%, it
gives me a message, and in that message %Appvar1% appears, and not the value
of it...If I go and type a set in a command prompt, "Appvar1" is not
present...

But if I go into the User's Environment variables section on my computer/
Properties / Advanced / Environment Variables, I see them, If I click on OK
/ OK, then the variables are now seems to be loaded, and I can use them...
They appear in Set command and typing %Appvar1% on the Run menu comes
back with the value of it...

Can anyone tell me how to set or reload user's environment variables so they
are seen by the system as soon as the script is done...

Thanks very much !!!

--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting



--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting
www.formationhy.com
Houman@formationhy.com

Re: VB Script that sets and load environment variables by Torgeir

Torgeir
Fri Jan 16 17:45:25 CST 2004

Houman Yahyaei wrote:

> Hi, I have a script that set environment variables in the following way :
>
> Set WshEnv = WshShell.Environment("USER")
>
> WshEnv("Appvar1") = xyz
>
> This works ok, and when going to the User's Environment variables section on
> the computer, all the custom variables are there, but the problem is they
> don't seem to be already loaded into memory or the value doesn't seems to be
> loaded by the OS...

Hi

(a side note first: the groups scripting.debugger, scripting.remote and
scripting.scriptlets are not relevant to you question really)

That is not how I experience it (Win2k and WinXP). After the script above is
finished, if I open a new command prompt and type set, I see the Appvar1
variable.

Try this and see if this works for you:

Set oShell = CreateObject("WScript.Shell")
Set oUserEnv = oShell.Environment("USER")
xyz = "abcxyz"
oUserEnv("Appvar1") = xyz

oShell.Run _
"%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", _
1, True


Note that if this newly created environment variable is to be available for the
script itself (or any child processes it starts), you will need to set it in the
process environment as well, as this script demonstrates:


Set oShell = CreateObject("WScript.Shell")
Set oUserEnv = oShell.Environment("USER")
Set oProcessEnv = oShell.Environment("PROCESS")

xyz = "123abcxyz789"
oUserEnv("Appvar1") = xyz
oProcessEnv("Appvar1") = xyz

oShell.Run "%comspec% /k set", 1, False


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Re: VB Script that sets and load environment variables by Houman

Houman
Sat Jan 17 10:07:32 CST 2004

Thanks for the reply, I have done the first example, but still the same
thing...

If I run the command : "%windir%\System32\RUNDLL32.EXE
user32.dll,UpdatePerUserSystemParameters" from the command prompt, I can see
my desktop icon refreshing, but the environment variables still not
loaded...

So I was wondering what else I could do, I also have configured the GPO that
is running this script to "Run Logon scripts Synchronously" and to "always
wait for the network at computer start-up and logon"...

I haven't tried your command on a WinxP box, but rather this is for a Win2K3
Terminal server, so I tried it in a user's TS session...

Thanks for all your help !!!!

--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting


"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:40087795.3FC69BC0@hydro.com...
> Houman Yahyaei wrote:
>
> > Hi, I have a script that set environment variables in the following way
:
> >
> > Set WshEnv = WshShell.Environment("USER")
> >
> > WshEnv("Appvar1") = xyz
> >
> > This works ok, and when going to the User's Environment variables
section on
> > the computer, all the custom variables are there, but the problem is
they
> > don't seem to be already loaded into memory or the value doesn't seems
to be
> > loaded by the OS...
>
> Hi
>
> (a side note first: the groups scripting.debugger, scripting.remote and
> scripting.scriptlets are not relevant to you question really)
>
> That is not how I experience it (Win2k and WinXP). After the script above
is
> finished, if I open a new command prompt and type set, I see the Appvar1
> variable.
>
> Try this and see if this works for you:
>
> Set oShell = CreateObject("WScript.Shell")
> Set oUserEnv = oShell.Environment("USER")
> xyz = "abcxyz"
> oUserEnv("Appvar1") = xyz
>
> oShell.Run _
> "%windir%\System32\RUNDLL32.EXE
user32.dll,UpdatePerUserSystemParameters", _
> 1, True
>
>
> Note that if this newly created environment variable is to be available
for the
> script itself (or any child processes it starts), you will need to set it
in the
> process environment as well, as this script demonstrates:
>
>
> Set oShell = CreateObject("WScript.Shell")
> Set oUserEnv = oShell.Environment("USER")
> Set oProcessEnv = oShell.Environment("PROCESS")
>
> xyz = "123abcxyz789"
> oUserEnv("Appvar1") = xyz
> oProcessEnv("Appvar1") = xyz
>
> oShell.Run "%comspec% /k set", 1, False
>
>
> --
> torgeir
> Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of the 1328 page
> Scripting Guide: http://www.microsoft.com/technet/scriptcenter
>
>



Re: VB Script that sets and load environment variables by Houman

Houman
Sat Jan 17 10:34:13 CST 2004

Ignore may last...
The GPO was on the computer OU ( since it's a TS ), with the GPO Loopback
enabled...

It took a reboot of the server ( or probably a GPUpdate would have done it
also, but there are test servers, so why the not.. ) for it to work ...

Thanks very very much !!!

--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting


"Houman Yahyaei" <news@formationhy.com> wrote in message
news:uY0BcPR3DHA.1816@TK2MSFTNGP12.phx.gbl...
> Thanks for the reply, I have done the first example, but still the same
> thing...
>
> If I run the command : "%windir%\System32\RUNDLL32.EXE
> user32.dll,UpdatePerUserSystemParameters" from the command prompt, I can
see
> my desktop icon refreshing, but the environment variables still not
> loaded...
>
> So I was wondering what else I could do, I also have configured the GPO
that
> is running this script to "Run Logon scripts Synchronously" and to "always
> wait for the network at computer start-up and logon"...
>
> I haven't tried your command on a WinxP box, but rather this is for a
Win2K3
> Terminal server, so I tried it in a user's TS session...
>
> Thanks for all your help !!!!
>
> --
> --
> Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
> IT Training and Consulting
>
>
> "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
> news:40087795.3FC69BC0@hydro.com...
> > Houman Yahyaei wrote:
> >
> > > Hi, I have a script that set environment variables in the following
way
> :
> > >
> > > Set WshEnv = WshShell.Environment("USER")
> > >
> > > WshEnv("Appvar1") = xyz
> > >
> > > This works ok, and when going to the User's Environment variables
> section on
> > > the computer, all the custom variables are there, but the problem is
> they
> > > don't seem to be already loaded into memory or the value doesn't seems
> to be
> > > loaded by the OS...
> >
> > Hi
> >
> > (a side note first: the groups scripting.debugger, scripting.remote and
> > scripting.scriptlets are not relevant to you question really)
> >
> > That is not how I experience it (Win2k and WinXP). After the script
above
> is
> > finished, if I open a new command prompt and type set, I see the Appvar1
> > variable.
> >
> > Try this and see if this works for you:
> >
> > Set oShell = CreateObject("WScript.Shell")
> > Set oUserEnv = oShell.Environment("USER")
> > xyz = "abcxyz"
> > oUserEnv("Appvar1") = xyz
> >
> > oShell.Run _
> > "%windir%\System32\RUNDLL32.EXE
> user32.dll,UpdatePerUserSystemParameters", _
> > 1, True
> >
> >
> > Note that if this newly created environment variable is to be available
> for the
> > script itself (or any child processes it starts), you will need to set
it
> in the
> > process environment as well, as this script demonstrates:
> >
> >
> > Set oShell = CreateObject("WScript.Shell")
> > Set oUserEnv = oShell.Environment("USER")
> > Set oProcessEnv = oShell.Environment("PROCESS")
> >
> > xyz = "123abcxyz789"
> > oUserEnv("Appvar1") = xyz
> > oProcessEnv("Appvar1") = xyz
> >
> > oShell.Run "%comspec% /k set", 1, False
> >
> >
> > --
> > torgeir
> > Microsoft MVP Scripting and WMI, Porsgrunn Norway
> > Administration scripting examples and an ONLINE version of the 1328 page
> > Scripting Guide: http://www.microsoft.com/technet/scriptcenter
> >
> >
>
>



Re: VB Script that sets and load environment variables by Torgeir

Torgeir
Sat Jan 17 11:14:54 CST 2004

Houman Yahyaei wrote:

> Thanks for the reply, I have done the first example, but still the same
> thing...
>
> If I run the command : "%windir%\System32\RUNDLL32.EXE
> user32.dll,UpdatePerUserSystemParameters" from the command prompt, I can see
> my desktop icon refreshing, but the environment variables still not
> loaded...

Hi

Loaded in the existing command prompt or in a new command prompt opened after
running the command?

If the former, that is by design, already started processes will not be updated
with new or changed environment variables, but new processes should get them, so
in a new command command prompt you should see it.


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Re: VB Script that sets and load environment variables by Houman

Houman
Mon Jan 19 12:21:08 CST 2004

I've tested it, and still the same thing...

environment variables are not loaded yet...

--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting
www.formationhy.com
Houman@formationhy.com

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:40096D8D.80CEBBCA@hydro.com...
> Houman Yahyaei wrote:
>
> > Thanks for the reply, I have done the first example, but still the same
> > thing...
> >
> > If I run the command : "%windir%\System32\RUNDLL32.EXE
> > user32.dll,UpdatePerUserSystemParameters" from the command prompt, I can
see
> > my desktop icon refreshing, but the environment variables still not
> > loaded...
>
> Hi
>
> Loaded in the existing command prompt or in a new command prompt opened
after
> running the command?
>
> If the former, that is by design, already started processes will not be
updated
> with new or changed environment variables, but new processes should get
them, so
> in a new command command prompt you should see it.
>
>
> --
> torgeir
> Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of the 1328 page
> Scripting Guide: http://www.microsoft.com/technet/scriptcenter
>
>