strNewPath  =”d:\newpath;”
strPathToReplace =”f:\pathToReplace;”

‘********************************* SET YOUR PATH ABOVE************************
‘Gregor Stefka
Const HKEY_LOCAL_MACHINE  = &H80000002
strComputer    = “.”
strKeyPath    = “SYSTEM\CurrentControlSet\Control\Session Manager\Environment”
strValueName    = “Path”

Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, strValueName,strValue
bAllreadySet    = InStr(1, strValue, strNewPath, 1)

‘Wscript.Echo  “The OldPath is: ” & strValue

‘Only add if its not set:
If bAllreadySet = 0 then
 If strPathToReplace =”” or InStr(1, strValue,strPathToReplace, 1) = 0 then
  strNewPath = strNewPath & strValue
 Else
  strNewPath = Replace(strValue, strPathToReplace, strNewPath)
 End If

 ‘ write the path
 oReg.SetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strNewPath
 ‘Wscript.Echo  “The New Path is: ” & strNewPath

End If