how to write C/C++ codes to set command-level environment variable?  
Author Message
qzy





PostPosted: Visual C++ General, how to write C/C++ codes to set command-level environment variable? Top

Either call Win32 API or some library.

I've tried to call system("set env=1"), defined in <process.h>. But it doesn't work. Seems nothing get added after I tried echo %env%.




Visual C++2  
 
 
Viorel.





PostPosted: Visual C++ General, how to write C/C++ codes to set command-level environment variable? Top

I hope this should work:

_putenv("env=1");

or

_tputenv(_T("env=1"));

or

SetEnvironmentVariableA("env", "1");

or

SetEnvironmentVariable(_T("env"), _T("1"));