Solved

How to set system variables using windows batch file.

Posted on 2011-03-23
7
799 Views
Last Modified: 2012-05-11
We have a Windows CAD program that looks to the System Variables under the Environmental Variables to find the location of it's configuration information.  Sometimes we need to use 2 sets of configuration information and right now that would require going into Environmental Variables and changing the System Variables each time.  I had thought about using a batch file to set the System Variable and then launch the CAD program but I wasn't sure if this would work.  I would then have a batch file they could run after to set them back to the original System Variables.  Any help and ideas are appreciated.
0
Comment
Question by:jwiang4u
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:silverkorn
ID: 35199004
is there a way to define what system variables the CAD program is looking for?

this way you could create two sets of the variables once and not need to change it. The problem with changing the system variable is having the user changing it back to use the first CAD program.
0
 
LVL 1

Author Comment

by:jwiang4u
ID: 35199068
There is no way to define what system variable the CAD program is going to use apart from the default, unfortunately.
0
 
LVL 12

Expert Comment

by:silverkorn
ID: 35199092
does the system variable need to be established prior to the start of the program or can you change the variable once the program has loaded?
0
Free book by J.Peter Bruzzese, Microsoft MVP

Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

 
LVL 1

Author Comment

by:jwiang4u
ID: 35199119
It has to be prior to the start of the program because the configuration folder contents are read while the program is starting.
0
 
LVL 12

Expert Comment

by:silverkorn
ID: 35199189
then it appears that your assumption is correct on changing the system variables with the batch file prior to the start of the program.

here is how to change the variables through the batch file:
http://support.microsoft.com/kb/121170

also make sure to have the batch file check to see what the variable is prior to changing it, this way if the variable is set correctly it then starts the program

the other option is to have the batch file ask the user which version they wish to run, this way you then only have one batch file to create and for the user to run.

let me know if you need help creating the batch file itself
0
 
LVL 1

Author Comment

by:jwiang4u
ID: 35199387
Thanks for the info.  I am trying to set the System Variable using the following MS link:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true

I did notice the following in the article which makes me a little worried:
"The set command alters variables in the current shell environment only."

Does this mean that once the batch file sets the variable and starts the program, the set variable goes away?  Does the program that is launched get this variable?
0
 
LVL 12

Accepted Solution

by:
silverkorn earned 500 total points
ID: 35199461
For Windowx XP you can use the SETX command to change the variables as detailed here:
http://technet.microsoft.com/en-us/library/cc755104(WS.10).aspx

to get the command you can download it here:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=49ae8576-9bb9-4126-9761-ba8011fabf38&displaylang=en
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 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