home *** CD-ROM | disk | FTP | other *** search
- /*
- * 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;
- }
-
-