Append to system path environment variable via login script
Posted on 2008-11-12
I have 400 machines in my domain environment. We're using a VBS login script which is called via group policy.
I need to append (not replace) a directory path to the existing system path environment variable on each PC. In other words, I can't mess up the existing path info a user has, but just add on to it. New machines are added or rebuilt each day, so this needs to be an ongoing thing and not just a one-time push.
Currently I have this working by using the following commands in the script:
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("SYSTEM")
WshEnv("Path") = WshEnv("Path") & ";M:\DB\whatever\"
The problem is that on some of the machines, not all, the new path keeps getting added on multiple times with each successive login. On one machine I have the same path appended 11 times and growing!
My question is how can I check for a previous instance of the same path I'm trying to add and then NOT add it if it is already there? Or, check for a previous instance(s) and then delete them before appending again?