Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Writing Environment variables ?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,126
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing Environment variables ?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Writing Environment variables ? - 6/6/2001 7:26:02 AM   
  dropme

 

Posts: 18
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
Reading environment variables is all very well, but how do
I write them ?
Using the WSH I am calling an application using:

set WshShell =
WScript.CreateObject("WScript.Shell")
WshShell.Run "Someprogram" , 1, TRUE

The problem is that this programs needs some Environment
variables set in order to work...
I found the:

Set WshUsrEnv =
WScript.Environment("User")
WshUsrEnv.Remove("EXAMPLE_1")

What I need is the corresponding:

WshUsrEnv.Add("MYVAR=Something")

But I can't find it..
 
 
Post #: 1
 
 Re: Writing Environment variables ? - 6/6/2001 7:27:42 AM   
  mid

 

Posts: 16
Score: 0
Joined: 6/4/2001
From: USA
Status: offline
You could use the WshShell.RegWrite method to

HKLM\System\CurrentControlSet\Control\Session
Manager\Environment

or

HKCU\Environment

(These are NT/2000 settings)

(in reply to dropme)
 
 
Post #: 2
 
 Re: Writing Environment variables ? - 6/6/2001 7:28:43 AM   
  dropme

 

Posts: 18
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
Thanks,

It was not quite what I needed as it also needs to run on win98.
But your answer got me thinking about what is really going on, so I
found another way of doing it, for anyone with a similar problem I
have included an example:

Set EnvObject = WshShell.Environment
Original=EnvObject.Item("Tmp")
EnvObject.Item("Tmp") = "c:\VbTmp"
WScript.Echo "Tmp dir changed from "
& Original & " To " &
EnvObject.Item("Tmp")
EnvObject.Item("MyVar") = "Something"
WScript.Echo "MyVar created, value :
" & EnvObject.Item("MyVar")


Thanks again,

(in reply to dropme)
 
 
Post #: 3
 
 Re: Writing Environment variables ? - 6/6/2001 7:29:45 AM   
  mid

 

Posts: 16
Score: 0
Joined: 6/4/2001
From: USA
Status: offline
I believe this only works in-process. It is not a permanent
change. Run it, then go to a command prompt and type 'set'. On
Win2K (don't know about 9x) it remained in its original state. The
description for the .item property states it 'returns a specified item
from a collection'.

(in reply to dropme)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing Environment variables ? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts