Setting environment Variables via VB Script 
Author Message
 Setting environment Variables via VB Script

I'm searching for a way to set system environment variables via vb script.
Reading Environment Strings is not the problem (expandenvironmentstrings)
but setting.

Can anybody help me ?

Thanks for every idea

Alex Fischer



Sun, 07 Aug 2005 18:17:05 GMT  
 Setting environment Variables via VB Script
You know, you're right.  The WSH help is not well written in this
regard, but I did finally find an example that illustates the
approach.  It was presented for the Remove methode as such ...

Example
The following code removes the Process environment variable TestVar.

'[VBScript]
Dim WshShell, WshEnv
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("PROCESS")
WshEnv("TestVar") = "Windows Script Host"  ' <-- this sets the
variable
WScript.Echo WshShell.ExpandEnvironmentStrings(_
  "The value of the test variable is: '%TestVar%'")
WshEnv.Remove "TestVar"
WScript.Echo WshShell.ExpandEnvironmentStrings(_
  "The value of the test variable is: '%TestVar%'")

(I modified the example slightly to deal with the Email client word
wrapping issue.)

Note that only "Process" variables are supported in Win 98/ME.  Win
NT/2000/XP also have "User" and "Volatile" environments.  Also, note
that varibles cannot be passed to the currently running console
(MS-DOS session) using this approach.  AFAIK, this can only be done by
echoing out a "SET TESTVAR=..." string to a secondary batch/cmd file
or 'FOR /F ...' statement.  See the earlier thread on Google ...

http://
groups.google.com/groups?threadm=Rfmdna3nYugzgd6jXTWcow%40fcc.net&rnum=13

That should all be one URL line, but is wrapped by my Email client.

Tom Lavedas
===========

Quote:

> I'm searching for a way to set system environment variables via vb script.
> Reading Environment Strings is not the problem (expandenvironmentstrings)
> but setting.

> Can anybody help me ?

> Thanks for every idea

> Alex Fischer



Mon, 08 Aug 2005 01:19:21 GMT  
 Setting environment Variables via VB Script

Quote:

> I'm searching for a way to set system environment variables via vb script.
> Reading Environment Strings is not the problem (expandenvironmentstrings)
> but setting.

Hi

Take a look at the Environment property

WSH\VBScript/Jscript 5.6 documentation download (script56.chm)
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

Setting environment variables permanent (WNT/W2k/WXP) from VBScript:

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

Set WshShell = 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 WshSystemEnv = WshShell.Environment("SYSTEM")

' Set your environment variable
WshSystemEnv("ASSET") = "1234"

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

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



Sun, 07 Aug 2005 21:59:49 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Setting Win 95 Environment via script ???

2. Refresh environment varible set by VB Script

3. Refresh environment varible set by VB Script

4. Set an environment variable in a VB program

5. Set an environment variable in a VB programm

6. How to set Environment Variable (PATH) with VB

7. How do you set environment variables in VB?

8. Set Environment Variable in VB 3.0

9. Set DOS Environment variable from VB 4.0??

10. setting PATH environment variable from VB 3.0 for Windows Pro

11. How to set an environment variable in VB?

12. How to set environment variables in VB

 

 
Powered by phpBB® Forum Software