Solved

Setting "Volatile" Environment Variables

Posted on 2009-06-30
6
1,510 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
Comment Utility
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
Comment Utility
top of the script....

setlocal

and at the end.....

endlocal
0
 
LVL 21

Expert Comment

by:AmazingTech
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:shacho
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your comments.

Mike
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now