Set wshShell = CreateObject( "WScript.Shell" )
Set wshSystemEnv = wshShell.Environment( "USER" )
wshSystemEnv( "TestVar" ) = "Value"
WScript.Echo wshSystemEnv( "TestVar" )
1. The system does not refresh environment variables.
2. A process inherits its environment block at init, so if the command window was already open prior to running the script it won't see the new variable.
3. Creating an environment variable in a custom script does not inject the new variable back into the EM process block and therefore it doesn’t get passed on to child actions/processes.
The example script will work to an extent.
Set doesn’t show the variable but it will be visible via the Environment Variables section in Computer > Properties.
Another solution is to use setx. This perhaps isn't as elegant as pure script as you have to shell out but it does refresh the variables and therefore lets processes outside the script see it.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "setx TestVar Value", False
However, because the scripted variable won't be injected into EM's process block the best solution is to use the Set Environment Variable action in EM.