• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1896

# Setting "Volatile" Environment Variables

Is there a shell / Dos command that can be used to set a current session only, "volatile" environment variable?

Mike

0
shacho
1 Solution

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

Commented:
top of the script....

setlocal

and at the end.....

endlocal
0

Commented:
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"

0

Author Commented:
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

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 Commented:

Mike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.