' Sauen "Add to Env Sys Path" ' Version 20120221 ' (c) Sauen.Com / J.Thomas Stokkeland 2012 - stoke _-@-_ sauen.com ' Licensed under GNU GPL v2 (General Public License version 2. www.gnu.org) ' ' Simple VBScript to add a new entry to system env variable PATH (Wintendo) ' Change the file type to a .vbs ' Only Tested on Wintendo Server 2008R2 ' ' Useful for automated installers with limitations, such as NSIS which has a string length issue, ' although I have not verified what the limitations are for vbscript, pretty sure it is 2 billion characters. ' ' This updates registry - to fully make the OS pick it up a reboot is needed after update. ' (If someone knows the trick to tell Bill gates to reload this, please let me know) ' ' use with cscript ' pass argument of new path that needs added to system %PATH% ' ' example cscript add_to_env_sys_path.vbs "X:\my\path\software\bin" ' ' I Always Recommend a backup is taken first: ' reg export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "c:\mybackups\my_env_reg.reg" /y ' Dim WshShell, envKey, orgPath,addPath,newPath Set WshShell = WScript.CreateObject("WScript.Shell") envKey = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\") orgPath = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path") if Wscript.Arguments.Count = 0 then WScript.Echo "Missing Path argument (None)" WScript.Quit(1) end if addPath = WScript.Arguments.Item(0) if addPath = "" then WScript.Echo "Missing Path argument (empty)" WScript.Quit(1) end if WScript.Echo "Original Path: " + orgPath WScript.Echo "Going to add: " + addPath if InStr(orgPath,addPath) = 0 then newPath = orgPath + ";" + addPath WScript.Echo "Going to look like: " + newPath WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path", newPath, "REG_EXPAND_SZ" WScript.Echo "Done" else WScript.Echo "You dork - looks like this one already exists... not doing anything - exiting code 0 as you wanted what was already in place" end if