Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Environment variables from VB - how?

Status
Not open for further replies.

stuck

MIS
Jan 16, 2002
9
0
0
US
OK, so I can get a DOS environment variable using ENVIRON().
But how do I set an environment variable from a VB program?

Any on out there kow
 
Use the API call:

Code:
Declare Function SetEnvironmentVariable lib "kernel32" Alias "SetEnvironmentVariableA" (ByVal lpName as string, ByVal lpValue as String)
lpName is the name of the environment variable to set. If it does not exist, this function will create it.

lpValue is the value to set. NULL value clears an existing value
 
Writing to the environment is pointless. Even with the API.

The environment is just a scratch pad for the current process. Once your VB App ends, it's environment goes too. Anything you put there is lost. Since the data is only available to your application, variables work much better. If you are looking for an inter process communication pathway, the environment of the current process is not the answer.

The Registry and old INI API provides the easiest way to pass values. Using them is much easier than finding and using your parent processes environment. MUCH EASIER.



Wil Mead
wmead@optonline.net

 
Thanks,
that works fine. (Needed to add the "as Boolean" at the end of the function declaration, but otherwise perfect!)

The VB program is a wrapper for an old DOS program that uses environment variables. The VB program remains active during the DOS program so all works fine. Gives me the possibility to use the VB wrapper to find the variables I want in the regisrty if they aren't sent in the environment. Seems to work hte way I want it. Better would be to re-write the DOS application........

Thanks again..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top