• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2664
  • Last Modified:

Setting Environment Variables in XP via batch file & SET.

I created a simple batch file that creates some install directories [this part works], it also calls to a .reg file [also working fine]. The reg file sets an EV however, it is not available until I logout and then back in if I call the app looking for this specific EV.  I figured I could just easily call SET from my batch file and temp set it for my current session; however, it does not appear it is working. If I run directly from the command line it works but not from the batch file.

It's been a long time since I really needed to do anything with batch files and certainly nothing under XP. Is this even possible?  If yes, any suggestions?
0
munkyxtc
Asked:
munkyxtc
  • 5
  • 3
1 Solution
 
Pete LongConsultantCommented:
Use the Set command
0
 
Pete LongConsultantCommented:
Setting environment variables
Use the set command to create, change, delete, or display environment variables. The set command alters variables in the current shell environment only.

To view a variable, at a command prompt, type:

set VariableName

To add a variable, at a command prompt, type:

set variablename=value

To delete a variable, at a command prompt, type:

set VariableName=

You can use most characters as variable values, including white space. If you use the special characters <, >, |, &, or ^, you must precede them with the escape character (^) or quotation marks. If you use quotation marks, they are included as part of the value because everything following the equal sign is taken as the value. Consider the following examples:

• To create the variable value new&name, type:

set varname=new^&name
 
• To create the variable value "new&name", type:

set varname="new&name"
 
• If you type set varname=new&name at the command prompt, an error message similar to the following appears:

"'name' is not recognized as an internal or external command, operable program or batch file."
 

Variable names are not case-sensitive. However, set displays the variable exactly as you typed it. You can combine uppercase and lowercase letters in your variable names to make your code more readable (for example, UserName).

 
Note

• The maximum individual environment variable size is 8192bytes.
 
• The maximum total environment variable size for all variables, which includes variable names and the equal sign, is 65,536KB.
 
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true
0
 
munkyxtcAuthor Commented:
@PeteLong

I understand how SET operates.  If I go to command window and type SET VARNAME=C:\DIRECTORY it works fine; however, when run from a btach file it does not perform the SET operation.  That is my question. Is there a reason it does not work from a batch file in XP?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
munkyxtcAuthor Commented:
Alternately if you have any idea how to refresh my current session without the need to logoff that would also be acceptable. I'm just looking to avoid the logout/login process to make this work.
0
 
Pete LongConsultantCommented:
What if you call Set from its location in the batchfile?

CALL SET VARNAME=C:\DIRECTORY
0
 
Pete LongConsultantCommented:
>>Alternately if you have any idea how to refresh my current session without the need to logoff

Off the top of my head no, but try (note: no = with this one :)

SETX VARNAME C:\WINDOWS

 that sets a permanant variable for the logged on user!
0
 
munkyxtcAuthor Commented:
I ended up using setx; I need to call the app twice before it allows you to open the application. I haven't determined if it's because the application initializes prior to the EV being set. In any event I'll award the points because it does work at this point. Not the most elegant solution and I needed to install a resource kit on the server to call setx but it does work. Thanks.
0
 
Pete LongConsultantCommented:
No Probs - Glad to help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now