?
Solved

Batch file to add variable to PATH

Posted on 2011-10-05
6
Medium Priority
?
622 Views
Last Modified: 2012-05-12
Hi,

Under system properties - Environment Variables - System variables - the Variable PATH I want to add the following ;C:\Program Files\Internet Explorer.

I have attached a screen shot.

I want to do this by using a batch script and I want to add to the existing variable.

Thanks

Luke

Environment-variable.bmp
0
Comment
Question by:luketr
6 Comments
 
LVL 9

Expert Comment

by:pritamdutt
ID: 36915649
My Quick Question do you want to store the changes permanently? or for runtime only.

in case you want to use for the current batchfile you can use the following command

SET PATH=%PATH%;new path

This will add your new path to existing list of PATHs

0
 

Author Comment

by:luketr
ID: 36915705
I've just tried it and it hasn't work, i need the change to be done permanetly.


SET PATH=%PATH%;C:\Program Files\Internet Explorer
0
 
LVL 22

Expert Comment

by:pivar
ID: 36915745
Hi,

You can use SETX to permanently set the PATH.

SETX PATH yourpath

Run SETX /? for help.

/peter
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Accepted Solution

by:
pritamdutt earned 2000 total points
ID: 36915772
1. You are required to surround path containing spaces with "" 
2. In order to make permanent changes for the system you need to administrative access to the system would be required. you could choose to use one of following methods
a) SETX.exe .. it had been available post Win XP SP 2 this works the same way as SET command, but makes permanent changes
b) use reg command to programatically set  registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment for the value of PATH
0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 36916039
You could use setx.exe from the Windows Resource kit or from M$ download:
http://www.microsoft.com/download/en/details.aspx?id=4200

Alternatively you can edit the registry key for "Path" in
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment]
The problem with changing registry keys is if you screw up the registry path your machine will become unusable - so be careful!

There's also the question of whether it's the local user's path or the system one for all users that you want to change.

There is a third party program called editpath which is reputedly good, but I haven't had firsthand experience:
http://www.brothersoft.com/editpath-316619.html
0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 36916052
That'll teach me not to leave a session open for a couple of hours before returning to a question - looks like pritamdutt beat me to most of that!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

862 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