Trying to add stuff to the system environment Path via batch, vbs or anything really.

This used to work in a .bat, but has stopped:

setx -m path "C:\addtopath;%PATH%" 

This used to work in VBS, but has also stopped:

Set WshShell = WScript.CreateObject("WScript.Shell") 
Set WshEnv = WshShell.Environment("SYSTEM") 
WshEnv("Path") = WshEnv("Path") & ";C:\addtopath"

This keeps saying invalid syntax when I try to modify the registry:

REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\Environment" /v Path /t REG_SZ /d "%path%;C:\addtopath" /f

I am really stumped on this one. I need a solution that will always work. I am running it as administrator, but it still not working.


  • 2
    What do you mean by "used to work, byt also stopped"? Any errors or just fails silently?
    – gronostaj
    Commented Jul 28, 2013 at 8:18
  • How long is your actual PATH value? There have been limits on the maximum length IIRC.
    – Mario
    Commented Jul 28, 2013 at 8:27
  • Was getting: Default option is not allowed more than '2' time(s). It did not exceed maxlength.
    – user241370
    Commented Jul 28, 2013 at 8:37
  • Double post: superuser.com/questions/625116/… Commented Jul 28, 2013 at 16:22
  • Shouldn't be Session Manager(A space between Session and Manager)
    – Marslo
    Commented Nov 27, 2014 at 6:57

2 Answers 2


try to add it into PATH using GUI, right click on My Computer select Properties, and find Environment Variables, then edit the value of PATH


In my case, I somehow had a " end up in the actual PATH value...

I had to type PATH into CMD, copy out the contents, and overwrite it with setx PATH "contents here". (Of course, don't make any mistakes when you do this.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .