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!

Create System environment variable in VB

Status
Not open for further replies.

kottan

Programmer
Jan 28, 2002
2
0
0
DE
HI,
I want to develop a litle program to create a system environment variable an give it a value.
In vbscript I used the following code:

Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WshEnv = WshShell.Environment("SYSTEM")
WshEnv("EXAMPLE")= "Test123"

and it works fine.

But now I want to use this functionality in a compiled application in VB and I didn't find a method to do so.
The vbscript code does not run.

Does anybody know how to create environment variables in VB?

Regards

kottan
 
Look at the API calls GetEnvironmentStrings, GetEnvironmentVariable and SetEnvironmentVariable. If you find the MSDN documentation too hard on this, rush out and buy Dan Appleman's Visual Basic Programmer's Guide to the Win32 API.

First though, I'd think very hard about whether you really need to be setting environment variables - you might do better using the registry.

Bill.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top