• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Appending to the System PATH from batch file?

Namuna

Platinum Member
Hopefully this is an easy answer...

I want to append a path to the global system path, permanently.

I'm already familiar with using:
SET PATH=c:\whatever\here;%PATH%

But this only seems to set the path while that command window is open, how do I make this change apply to the system permanently?

Thanks!
 
use "reg update" from batch file to update registry variables. reboot will be required post editing path in registry.
 
reg update sounds like a plan...But how do you specify a variable in a reg update line?

What I mean is, I don't want to disturb whatever PATH the user already has, only want to append another path.

With the set command you can do the ;%PATH% at the end so it doesn't disturb what's already there...Is the same syntax allowed when doing 'reg update' ?

thanks.
 
The command line can't do what you are looking for without some outside utilities.
It might be easier in vbscript if you can use that. Save the following as a .vbs file



Sub AddToSystemPath (strnewPath)
Set WshShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next

'Read the system path. Exit on errors.
strPath = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path")

If Err.Number <> 0 Then Exit Sub
If Instr(strPath, strnewPath) > 0 Then 'if the variable is already in the path then alert
MsgBox "Already in the path"
Else
Dim seperatorchar
If Right(strPath,1) =";" Then
seperatorchar = ""
Else
seperatorchar = ";"
End if
strPath = strPath & seperatorchar & strNewPath

WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path", strPath, "REG_EXPAND_SZ"
If Err.Number = 0 Then
WScript.Echo "System path updated to:" & vbCrLf & strPath
Else
WScript.Echo "Path not updated - no updates necessary."
End If
End if
End Sub

'call to add the path to the system path
AddToSystemPath "C:\Temp"
 
Just figured I'd answer your question for the hell of it, even though KB has given another method. Yes %path% can be used anywhere on the dos level, which means from echo, a for command, or even reg update.

in windows XP this would be the proper command format:

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "c:\whatever\here;%path%" /f
 
Back
Top