2

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).

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
d3vdpro
  • 2,572
  • 4
  • 23
  • 28

4 Answers4

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
  • 316,376
  • 76
  • 642
  • 652
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
  • 286,686
  • 52
  • 238
  • 332
  • 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
  • 13,366
  • 11
  • 56
  • 99
  • 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
  • something like set path=%path%;new_path – Dani May 06 '10 at 20:32
  • 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
  • 145
  • 4