B
BrianB
I have a VB.NET application that needs to extract the environment variables
(EV) set by a bat file named SetVars.cmd. I would think the easiest way
would be to have my VB run the cmd file and then just read the environment
variables that are set. But I haven't found a way to do that. It appears
that the cmd file runs as its own process and the EV that are set are
promptly forgotten as soon as the cmd file finishes. For my test the cmd
file contains one line:
set myjunk=v1.2.3.4
The VB.net code that I've tried follows. Neither returns the value set in
the cmd file. Any suggestions how I can do this would be greatly
appreciated.
wsh = CreateObject("WScript.Shell")
wsh.Run(.CollectionFolder & "\SetVars.cmd", 0, 1)
MsgBox("EV = " & Environment.GetEnvironmentVariable("myjunk"))
startInfo = New System.Diagnostics.ProcessStartInfo(.CollectionFolder &
"\SetVars.cmd")
pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit()
MsgBox("EV = " & Environment.GetEnvironmentVariable("myjunk"))
Brian
(EV) set by a bat file named SetVars.cmd. I would think the easiest way
would be to have my VB run the cmd file and then just read the environment
variables that are set. But I haven't found a way to do that. It appears
that the cmd file runs as its own process and the EV that are set are
promptly forgotten as soon as the cmd file finishes. For my test the cmd
file contains one line:
set myjunk=v1.2.3.4
The VB.net code that I've tried follows. Neither returns the value set in
the cmd file. Any suggestions how I can do this would be greatly
appreciated.
wsh = CreateObject("WScript.Shell")
wsh.Run(.CollectionFolder & "\SetVars.cmd", 0, 1)
MsgBox("EV = " & Environment.GetEnvironmentVariable("myjunk"))
startInfo = New System.Diagnostics.ProcessStartInfo(.CollectionFolder &
"\SetVars.cmd")
pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit()
MsgBox("EV = " & Environment.GetEnvironmentVariable("myjunk"))
Brian