Passing environment variables to a process in PowerShell 2.0 when the variable is changed multiple times -


i'm having issue when comes passing corresponding environment variables process. below can see part of code can understand i'm trying do.

i have 2 exe files need run. processes run updates based on location of environment variable %mainfiles%. when run code seems exe files not recognize change. however, when under computer properties see variables changed correctly.

does know how force process recognize change? thanks

while ($i -lt $size) {   if ($tempenv[$i] -eq "done"){     $exitcode="completed"     return   } else {     $temp = $tempenv[$i]     write-host ("starting update  " + $temp) -foregroundcolor "green"      [system.environment]::setenvironmentvariable("mainfiles", "$temp","machine")     [system.environment]::getenvironmentvariable("mainfiles","machine")     copy-item $copyinstalldata -destination $temp     $process = start-process xmlupgrade.exe -workingdirectory "c:\program files\dtm" -wait     $process = start-process update.exe -workingdirectory "c:\program files\dtm" -wait . . . 

this line makes env var change permanent:

[system.environment]::setenvironmentvariable("mainfiles", "$temp","machine") 

unfortunately powershell has launched before set this. env block snapshotted @ launch time. environment 2 spawned processes inherit.

to 2 processes launch correct environment variable value first:

$env:mainfiles = $temp 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -