Solved

Setting "Volatile" Environment Variables

Posted on 2009-06-30
6
1,598 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
[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
  • Learn & ask questions
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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)

749 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