|
|
Subject:
Windows XP: Setting environment variables via windows scripting
Category: Computers > Programming Asked by: marvingreenberg-ga List Price: $12.00 |
Posted:
24 Jul 2003 08:59 PDT
Expires: 31 Jul 2003 07:04 PDT Question ID: 234631 |
I need to know how, using windows scripting (preferably jscript) to set environment variables such that the new values are immediately available for new commands that are run. I have a windows script (javascript) that sets environment variables in the registry. Here is a relevant bit: var shell = WScript.CreateObject("wscript.shell"); // Set some string variables OMhome and append to the path shell.RegWrite ("HKCU\\Environment\\TENA_OM_HOME", OMhome, "REG_SZ" ); shell.RegWrite ("HKCU\\Environment\\PATH", path, "REG_SZ" ); Although this sets the values in the registry, the values are not added to the environment until a reboot or until you view the current environment using MyComputer/Properties/Advanced/Environment and click OK. This is verified by opening a CMD.EXE shell and typing set PATH. Is there a scripting command to explicitly force Windows (Explorer?) to reread a particular environment variable from the registry? |
|
There is no answer at this time. |
|
Subject:
Re: Windows XP: Setting environment variables via windows scripting
From: cleverclever-ga on 24 Jul 2003 10:39 PDT |
Set An Environment Variable Via WMI From a Google post. Note: this works great for modifying a variable for all Terminal Server sessions as well. The example below creates a variable named %RouterStatus% with the value of UP in the SYSTEM environment on a server named Mort. - AKA SetWmiEnvVar "MORT", "<SYSTEM>", "RouterStatus", "UP" Sub SetWmiEnvVar( Host, sContext, sVarName, sValue) ' Sets an environment variable on an arbitrary host via WMI ' NOTE: This will of course not affect currently running ' processes. ' For a systemwide value, use <SYSTEM> as context ' for default user, use <DEFAULT> ' otherwis,e use the specific user's name ' Get the class object itself Dim EnvClass, EnvVarInst Set EnvClass = GetObject("WinMgmts://" & Host _ & "/root/cimv2:Win32_Environment") ' Make a new instance of that class Set EnvVarInst = EnvClass.SpawnInstance_ ' File in the key props and props of interest on that instance EnvVarInst.UserName = sContext EnvVarInst.Name = sVarName EnvVarInst.VariableValue = sValue ' Write the new instance in to WMI EnvVarInst.Put_ End Sub |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |