Solved

Setting "Volatile" Environment Variables

Posted on 2009-06-30
6
1,559 Views
Last Modified: 2013-11-09
Is there a shell / Dos command that can be used to set a current session only, "volatile" environment variable?

Mike

0
Comment
Question by:shacho
6 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 24751591
What do you mean by "volatile" - give an example.

(The SET command should set any environment variable you want for the duration of the command prompt).
0
 
LVL 66

Expert Comment

by:johnb6767
ID: 24751652
top of the script....

setlocal

and at the end.....

endlocal
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 24752404
You'll probably need to use a vbscript file to add in the volatile envrionment variable.

After it's added start a new command prompt.

Your question should be worded as:

Is there a shell / Dos command that can be used to for the current user's logged on session only, i.e setting the "volatile" environment variable?
set shell = WScript.CreateObject("WScript.Shell")
set volatile = shell.Environment("VOLATILE")
volatile("VarName") = "Var Value"

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:shacho
ID: 24791511
I understand and frequently use the VBScript approach AmazingTech described, but I am not terribly familiar with shell scripting so please bear with me if this question sounds nonsensical.  The goal here is to create an Environment Variable of the "Volatile" flavor named "PATH" that exposes the location of a dll long enough for a subsequently loaded application to see it.  The way I am doing this now is precisely as AmazingTech describes.  However, this approach has a pitfall; the script has to run its course and exit before the variable is exposed to the application.  Setting up the variable and launching the app within the same script does not work.  So I was thinking that perhaps if I tried to achieve this with a batch file instead of a VBScript, my results would be different, so I was inquiring about the syntax.  Set and Setlocal as far as I can tell dimension and fill variables for the batch file to use - but I don't really understand the relationship between these variables and the "Environment Variables" that are accessible via the Windows GUI or the WScript.Shell methods.  Since "Set" with no parameters reveals in the shell them there is clearly some relationship, but I don't know what it is.  Can you help me understand this?

Mike
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 24792218
If you're trying to add to the path statement, then a simple batch file of:

@echo off
set path=%path%;x:\path\to\your\file.dll
start "" x:\path\to\your\application.exe


Variables set in command prompts "reset" upon exiting the command prompt and only apply to that command prompt - unless you use something like setx
0
 

Author Comment

by:shacho
ID: 24902559
Thanks for your comments.

Mike
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question