How can I set several environment variables with a VB script. These will be
system Environment variables.
Thanks

Paul

Re: Script in Environment varaible by Torgeir

Torgeir
Fri Aug 13 15:22:33 CDT 2004

Paul Ilacqua wrote:

> How can I set several environment variables with a VB script.
> These will be system Environment variables.
Hi

Create/set/change environment variables permanent (WNT/W2k/WXP
from VBScript:

'Example for setting a environment variable with name "ASSET"
and value "1234"

'--------------------8<----------------------
Set oShell = CreateObject("WScript.Shell")

' makes environment settings permanent and for all users
' Use "USER" instead of "SYSTEM" to set it for current
' user only, or "PROCESS" to set it for current process only
Set oWshSystemEnv = oShell.Environment("SYSTEM")

' Set your environment variable
oWshSystemEnv("ASSET") = "1234"
'--------------------8<----------------------


For Win9x/WinME, only "PROCESS" is available.


For SYSTEM and USER, you might need a logoff/logon to make the
changes take affect.


WSH 5.6 documentation (local help file) can be downloaded
from here if you haven't got it already:

http://msdn.microsoft.com/downloads/list/webdev.asp


--
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/default.mspx

Re: Script in Environment varaible by Paul

Paul
Fri Aug 13 16:34:57 CDT 2004

Torgeir,
Thank You very much.
Paul
"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:OjQ3ONXgEHA.1344@TK2MSFTNGP11.phx.gbl...
> Paul Ilacqua wrote:
>
> > How can I set several environment variables with a VB script.
> > These will be system Environment variables.
> Hi
>
> Create/set/change environment variables permanent (WNT/W2k/WXP
> from VBScript:
>
> 'Example for setting a environment variable with name "ASSET"
> and value "1234"
>
> '--------------------8<----------------------
> Set oShell = CreateObject("WScript.Shell")
>
> ' makes environment settings permanent and for all users
> ' Use "USER" instead of "SYSTEM" to set it for current
> ' user only, or "PROCESS" to set it for current process only
> Set oWshSystemEnv = oShell.Environment("SYSTEM")
>
> ' Set your environment variable
> oWshSystemEnv("ASSET") = "1234"
> '--------------------8<----------------------
>
>
> For Win9x/WinME, only "PROCESS" is available.
>
>
> For SYSTEM and USER, you might need a logoff/logon to make the
> changes take affect.
>
>
> WSH 5.6 documentation (local help file) can be downloaded
> from here if you haven't got it already:
>
> http://msdn.microsoft.com/downloads/list/webdev.asp
>
>
> --
> 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/default.mspx



Re: Script in Environment varaible by Andrew

Andrew
Mon Sep 13 13:11:59 CDT 2004

This is a multi-part message in MIME format.
--------------080600030606020202030003
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Torgeir Bakken (MVP) wrote:

> Paul Ilacqua wrote:
>
>> How can I set several environment variables with a VB script. These
>> will be system Environment variables.
>
> Hi
>
> Create/set/change environment variables permanent (WNT/W2k/WXP from
> VBScript:
>
> 'Example for setting a environment variable with name "ASSET" and
> value "1234"
>
> '--------------------8<----------------------
> Set oShell = CreateObject("WScript.Shell")
>
> ' makes environment settings permanent and for all users
> ' Use "USER" instead of "SYSTEM" to set it for current
> ' user only, or "PROCESS" to set it for current process only
> Set oWshSystemEnv = oShell.Environment("SYSTEM")
>
> ' Set your environment variable
> oWshSystemEnv("ASSET") = "1234"
> '--------------------8<----------------------

Yeah but how do you set the environment variable of the caller? I ask
because I effectively want to do something like this in a cmd script:

@echo off
rem Set environment properly
cscript setenv.vbs
rem Verify environment
verify_env.cmd

Problem is that while setenv.vbs sets the env it does *not* stick after
cscript exits. When verify_env.cmd runs the environment variable is
*not* set! Note that if I replaced the "cscript..." line with a simple
"set var=..." it works and if I replace the "cscript..." line with an
execution of say setenv.cmd (where it simply does set var=...) then it
works. And even if I call a setenv.cmd with "call setenv.cmd" it still
works. So then, how can I set environment variables from vbscript such
that they are still effective in the parent's environment?
--
If you can smile when things go wrong, you have someone in mind to blame.

--------------080600030606020202030003
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Torgeir Bakken (MVP) wrote:
<blockquote cite="midOjQ3ONXgEHA.1344@TK2MSFTNGP11.phx.gbl" type="cite">Paul
Ilacqua wrote:
<br>
<blockquote type="cite">How can I set several environment variables
with a VB script.
These will be system Environment variables.
<br>
</blockquote>
Hi
<br>
<br>
Create/set/change environment variables permanent (WNT/W2k/WXP
from VBScript:
<br>
<br>
'Example for setting a environment variable with name "ASSET"
and value "1234"
<br>
<br>
<tt>'--------------------8&lt;----------------------
<br>
Set oShell = CreateObject("WScript.Shell")
<br>
<br>
' makes environment settings permanent and for all users
<br>
' Use "USER" instead of "SYSTEM" to set it for current
<br>
' user only, or "PROCESS" to set it for current process only
<br>
Set oWshSystemEnv = oShell.Environment("SYSTEM")
<br>
<br>
' Set your environment variable
<br>
oWshSystemEnv("ASSET") = "1234"
<br>
'--------------------8&lt;----------------------
</tt><br>
</blockquote>
Yeah but how do you set the environment variable of the caller? I ask
because I effectively want to do something like this in a cmd script:<br>
<br>
<tt>@echo off<br>
rem Set environment properly<br>
cscript setenv.vbs<br>
rem Verify environment<br>
verify_env.cmd<br>
</tt><br>
Problem is that while setenv.vbs sets the env it does <b>not</b> stick
after cscript exits. When verify_env.cmd runs the environment variable
is <b>not</b> set! Note that if I replaced the "cscript..." line with
a simple "set var=..." it works and if I replace the "cscript..." line
with an execution of say setenv.cmd (where it simply does set var=...)
then it works. And even if I call a setenv.cmd with "call setenv.cmd"
it still works. So then, how can I set environment variables from
vbscript such that they are still effective in the parent's environment?<br>
-- <br>
If you can smile when things go wrong, you have someone in mind to
blame.<br>
</body>
</html>

--------------080600030606020202030003--