Append system path variable

lokiju

Lifer
May 29, 2003
18,526
5
0
I'm looking for the cleanest and easiest way to append to the Path variable under System Variables under Environment Variables in Windows OS's.

I've Google'd around for ways to do this with Powershell, command prompt commands and editing the registry.

While editing the registry directly with my own interactions is an option, I'm trying to figure out how to script this so I can apply it on a large scale.

The registry path is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path

Has anyone done this before successfully and know a scrip/command/method for accomplishing this?

The key thing is I'm trying to APPEND to the existing system path, not overwrite what's already there.

Thanks.
 

MerlinRML

Senior member
Sep 9, 2005
207
0
71
You can get the contents from the registry using reg query, manipulate the string through your script, then update value with a reg add.

One issue to be aware of is that the OS does not realize the value has been modified so it does not issue an event to the shell to reload the contents of that registry key. You may have to reboot or logout/login for the new values to be detected.
 

stlcardinals

Senior member
Sep 15, 2005
729
0
76
If you can get a hold of a copy of Windows PowerShell 2.0 Administrator's Pocket Consultant, the author goes into detail of how to do this with the SETX command on page 58.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Even if you edit the registry manually you'll need to refresh the environment somehow, usually by forcing the user to log off and back on again. The system control panel seems to have some magic that updates it for the current session in their Apply button code, but I don't know how they do it.
 

lokiju

Lifer
May 29, 2003
18,526
5
0
If you can get a hold of a copy of Windows PowerShell 2.0 Administrator's Pocket Consultant, the author goes into detail of how to do this with the SETX command on page 58.

I think I might actually have that handy somewhere.

I'll look it over.