Export Environment Variable From a Cmd line VB Exe

J

Jimmy

Hello,
I need to have a VB progam Decrypt a Password, and
Export it Back to the Calling CMD.Exe window as an
Environment Variable that can be used later then the Batch
file. So far, I've tried Setting the Variable in the VB
Code, but it is Destroyed when the code completes. I've
tried using the SETX and SETENV Utilities that Save the
Variable and Value to the Registry (Not what I would
prefer, but I can clean up later), But then the value is
Still not visable to the Current CMD Console Window or any
of it's children. I've Tried using the SendMessageTimeout
Call, but It Doesnt look like CMD.EXE is listening for
that message. Does Anyone Have Any Suggestions ?
 
C

Craig Barkhouse

I don't know of any way to change the environment of another process. CMD
scripts are able to change the environment because they are executed within
the same cmd.exe process.

One thing you could do is have your VB script output the password to stdout,
then have your CMD script get it as follows:

for /f "delims=" %%i in ('decrypt.vbs') do @set pw=%%i

This might pose security considerations though.
 
M

Matt Hickman

Jimmy said:
Hello,
I need to have a VB progam Decrypt a Password, and
Export it Back to the Calling CMD.Exe window as an
Environment Variable that can be used later then the Batch
file. So far, I've tried Setting the Variable in the VB
Code, but it is Destroyed when the code completes. I've
tried using the SETX and SETENV Utilities that Save the
Variable and Value to the Registry (Not what I would
prefer, but I can clean up later), But then the value is
Still not visable to the Current CMD Console Window or any
of it's children. I've Tried using the SendMessageTimeout
Call, but It Doesnt look like CMD.EXE is listening for
that message. Does Anyone Have Any Suggestions ?

You can use the VB program to build a batch file which sets the
environemtal variable. then call that batch file from your
cmd.exe window.

Or you can return the decrypted password from your VB program
and gain access to the result using the following FOR syntax:
FOR /F %variable IN ('command') DO command [command-parameters]
e.g.: for /F %g in ('decrypt.vbs') do set password=%g

To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.

--
Matt Hickman
I think you are a romantic. Now this is a very romantic
age, so there is no room for romantics; it calls for
practical men. A hundred years ago you would have
made a banker or a professor and you could have worked
out your romanticism by reading fanciful tales and
dreaming about what you might have been if you hadn't
the misfortune to be born into a humdrum period. But
this happens to be a period when adventure and romance
are part of daily existence. Naturally it takes very
practical people to cope with it.
- Robert A. Heinlein (1907-1988)
_Tunnel in the Sky_ (c 1955)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top