home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Win32 Under the API
/
ProgrammingWin32UnderTheApiPatVillani.iso
/
Chapter9
/
9-3
/
env_ex.c
Wrap
C/C++ Source or Header
|
2000-07-09
|
739b
|
35 lines
/*
* Environment example env_ex.c
*
* Get an environment variable, modify it and set it. Demonstrates the fundamental
* methods of manipulating Win32 environment variables.
*/
#include <stdio.h>
#include <windows.h>
#define MAXBUF 4096
int main(int argc, char* argv[])
{
char szBuffer[MAXBUF];
printf("Hello world\n");
if(0 == GetEnvironmentVariable("PATH", (LPTSTR)szBuffer, MAXBUF))
{
printf("PATH variable is not defined\n");
}
else
{
printf("old PATH = \"%s\"\n", szBuffer);
strcat(szBuffer, ";C:\\SOME_DIR");
SetEnvironmentVariable("PATH", szBuffer);
GetEnvironmentVariable("PATH", (LPTSTR)szBuffer, MAXBUF);
printf("new PATH = \"%s\"\n", szBuffer);
}
return 0;
}