HEELPBOOK - Windows System environment variable, changes not getting reflected in CMD prompt (VBScript) ############## ####### With Restart You could add or modify an environment variable creating or modifing a registry key in Windows, using the following simple script, for example, we will add the environmet variable named CATALINA_HOME with value C:\Tomcat5 to the system: set WshShell = CreateObject("WScript.Shell") WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\CATALINA_HOME", "C:\Tomcat5" , "REG_EXPAND_SZ" The drawback will be that this variable will not be available to %COMSPEC% (or simply CMD) through the SET command. To let this change active you will have to restart your computer. ####### Without Restart Actually, adding/modifying environment variable using registry is a bit raw way. We might be creating some inconsistencies by doing so. So, the ideal way of doing is by using the collection which is dedicated to the environment variables, WshEnvironment. Now write the following script to add system environment variable: Set wshshell = CreateObject("WScript.Shell") Dim WshSySEnv Set WshSysEnv = wshshell.Environment("SYSTEM") WshSysEnv("1VINOD") = "1Vinod" WshSysEnv("2VINOD") = "2Vinod" Set WshSySEnv = Nothing Save this code in vbs file, execute the vbs file. Now, you will get the 2 environment variables in cmd prompt without restarting the system. Similar script for removing the variables: Set wshshell = CreateObject("WScript.Shell") Dim WshSySEnv Set WshSysEnv = wshshell.Environment("SYSTEM") WshSysEnv.Remove("1VINOD") WshSysEnv.Remove("2VINOD") Set WshSySEnv = Nothing This also does not require any restarts/logon-logoffs. Enjoy! ############ ARTICLE INFO ############# Article Month: February Article Date: 26/02/2013 Permalink: http://heelpbook.altervista.org/2013/windows-system-environment-variable-changes-not-getting-reflected-in-cmd-prompt-vbscript/ Source: http://stackoverflow.com/questions/5898346/vbscript-windows-system-enviroment-variable-changes-not-getting-reflected-in Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook Linkedin: http://it.linkedin.com/pub/stefano-maggi/27/73a/b20 Google+ : https://plus.google.com/116990277568167008289/posts