[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# Setting "Volatile" Environment Variables

Posted on 2009-06-30
Medium Priority
1,771 Views
Is there a shell / Dos command that can be used to set a current session only, "volatile" environment variable?

Mike

0
Question by:shacho
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 96

Expert Comment

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

ID: 24751652
top of the script....

setlocal

and at the end.....

endlocal
0

LVL 21

Expert Comment

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"

0

Author Comment

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 96

Accepted Solution

Lee W, MVP earned 2000 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

ID: 24902559

Mike
0

## Featured Post

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
###### Suggested Courses
Course of the Month15 days, left to enroll