I want to make a batch file for setting the %PATH% environment variable permanently - ie adding a value to the path permanently (in Windows XP).
Asked
Active
Viewed 2,985 times
2
-
i want to make a batch file (using cmd commands) – d3vdpro Nov 05 '09 at 06:55
-
if so then I think this belongs on ServerFault. Or is writing a .BAT file considered programming? :-) – Warren P Nov 10 '10 at 14:15
4 Answers
5
On more recent OSes you can use setx
which allows pretty fine-grained control as for where the variables are stored. Not available on XP, though, unless you install the Windows Server 2003 Support Tools.

Joey
- 344,408
- 85
- 689
- 683
-
SETX works but the syntax is really picky and so its easy to make a mistake. – djangofan Mar 26 '12 at 16:16
-
Yes, `setx` is not a drop-in replacement for `set`, despite the similar name. – Joey Mar 26 '12 at 18:36
1
you can use vbscript (or command line reg) to change the PATH environment variable
eg vbscript
Set WshShell = WScript.CreateObject("WScript.Shell")
strReg = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path"
strSetting = WshShell.RegRead(strReg)
strNewSetting = strSetting&";c\test" 'insert path to current PATH
WScript.Echo strNewSetting
WshShell.RegWrite strReg, strNewSetting

ghostdog74
- 327,991
- 56
- 259
- 343
-
This is what programmers looking for this question will want to find. The accepted answer is a ServerFault (admin/batchfile) answer not a programming answer. – Warren P Nov 10 '10 at 14:15
0
My-Computer - Properties, Advanced system settings -> environment variables. Set it there. (I hope that I got the right path here)

Dani
- 14,639
- 11
- 62
- 110
-
you are missing a right-click (people will double-click on my computer by default) and the tab is named "advanced". another way: start menu/control panel/system then advanced/environment variables. of course this works only if the user uses classic view in the control panel... – Adrien Plisson Nov 05 '09 at 07:36
-
COuld you anser me how to optain exactly the result you describe in your answer, but doing it from a script file? – Jesper Rønn-Jensen May 06 '10 at 09:01
-
-
that would last until you exit from that command prompt session. The question said "permanently". Setx (on systems that have it) works like SET but it's permanent. – Warren P Nov 10 '10 at 14:16
0
You can use setx.exe to set environment variables from a batch file or command line. I believe it's included with Vista and 7. For XP, you can find it in the SP2 Support Tools.

Joel Baker
- 155
- 5