Add a line to System variables path with batch file

batch-file, path, windows

Solution

echo Set objShell = CreateObject( "WScript.Shell" ) > %TEMP%\sp.vbs
echo Set objSystemEnv = objShell.Environment( "SYSTEM" ) >> %TEMP%\sp.vbs
echo objSystemEnv("Path") = objSystemEnv("Path") ^& ";C:\Program Files (x86)\Java\jre7\bin" >> %TEMP%\sp.vbs
cscript.exe /nologo %TEMP%\sp.vbs
del %TEMP%\sp.vbs

This CMD must run elevated, otherwise cscript.exe will just write "Permission denied" and nothing will happen.

Problem

I've been searching for a script that would let me add text to the end of the current System variables Path. Is there any suggestions to how I could do that? (spesificly, adding ";C:\Program Files (x86)\Java\jre7\bin\java.exe" to the existing text)

Original source