Function Setenv() Foundation

Sets the contents of an operating system environment variable.

Setenv( <cSetVar>, <cValue> ) --> lSuccess
<cSetVar> is a character string indicating the name of an operating system environment variable. It can be specified in upper or lower case letters.
<cSetVar> is a character string representing the value of the the environment variable.

The function returns .T. (true) if the environment variable could be set, otherwise it returns .F. (false).


The function Setenv() is used to set new or alter current environment variables of the active process. Note that it cannot be used to change the environment of other processes. However, if a new process is spawned using the RunShell() function, the new process inherits the environment variables of the active process. Therefore, Setenv() is suitable to define the environment variables for a new process.

Changing the SET PATH environment variable
// The example demonstrates how to alter an 
// existing environment variable. 

   LOCAL cPath := GetEnv( "PATH" ) 

   IF .NOT. Right(cPath,1) == ";" 
      cPath += ";" 

   ? cPath                          // result: C:\WINNT; 
   cPath += "C:\BIN;" 

   ? Setenv( "PATH", cPath )        // result: .T. 

   ? Getenv( "PATH" )               // result: C:\WINNT;C:\BIN; 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.