Solved

Setting Environment Variables in XP via batch file & SET.

Posted on 2007-11-15
8
2,650 Views
Last Modified: 2010-05-18
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
Comment
Question by:munkyxtc
  • 5
  • 3
8 Comments
 
LVL 57

Expert Comment

by:Pete Long
ID: 20288709
Use the Set command
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 20288721
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
 
LVL 4

Author Comment

by:munkyxtc
ID: 20288940
@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
 
LVL 4

Author Comment

by:munkyxtc
ID: 20288965
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 57

Expert Comment

by:Pete Long
ID: 20289005
What if you call Set from its location in the batchfile?

CALL SET VARNAME=C:\DIRECTORY
0
 
LVL 57

Accepted Solution

by:
Pete Long earned 50 total points
ID: 20289024
>>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
 
LVL 4

Author Comment

by:munkyxtc
ID: 20295676
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
 
LVL 57

Expert Comment

by:Pete Long
ID: 20296921
No Probs - Glad to help
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Batch file to delete a folder 5 71
XP as a dual boot with Windows 10 10 90
Windows Batch File - Count Down 4 62
Remove header from multiple csv files using batch script 11 65
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

18 Experts available now in Live!

Get 1:1 Help Now