[RESOLVED] from DOS, set test=hello and pass to VB6
Hi,
Hoping someone can explain to a learner how to read a variable set in a dos batch file from vb script:
My VB script runs a batch file which sets a variable. when the batch file finishes and control is passed back to VB i then need to be able to determine what that variable has been set to.
Re: from DOS, set test=hello and pass to VB6
environ(envoiromentalvariable) will return permanent envoiromental variables, but ones set in a dos session are only available within that session, when i open a second dos session that vairable does not exist in it
Re: from DOS, set test=hello and pass to VB6
Thanks for the reply,
I understand what you say but wanted to know if there was a way to access non permanant variable, ie those i set in DOS if i keep the dos session alive?
Re: from DOS, set test=hello and pass to VB6
not that i know of, but i have seen post here about console sessions, that may or may not be of some value, a simple solution would be to put the variable into a temp text file, that your program can then read
Re: from DOS, set test=hello and pass to VB6
Again thanks for the reply.
I cannot use a txt file (one of my first thoughts) as i cannot write to the hard drive also I need to keep the solution as simple as possible, i still have 'L' plates :blush: .
Whilst i didnt want to write to the registry, i haven't understood this yet, seems to be a lot of code!, this is what i have resorted to.
In case this thread may be viewed by others trying to learn (like me) and wanting to do something similar, Below i outline my solution.
- Synchronously shell to dos and run batch file
- use reg add in batch file to set a registry string under HKEY_CURRENT_USER\Software\VB and VBA Program Settings\yourkey\yourkey
- when batch file terminates and control is returned to vb use GetSetting (<ApplicationName>, <Section>, <Key>[, Default]), to get value set in batch file.
If you dont shell synchronously then the value returned by GetSetting may not reflect correctly the value set from DOS.
As i have a solution that works, even though not a definative answer to my question i consider this resolved.
Any comment appreciated. :wave:
Re: [RESOLVED] from DOS, set test=hello and pass to VB6
funny as it may seem writing to the registry still means writing to the hard disk, but if the solution works for you then that is good enough