Function Setenv() Foundation

Sets the contents of an operating system environment variable.

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

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

Description

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.

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

PROCEDURE Main 
   LOCAL cPath := GetEnv( "PATH" ) 

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

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

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

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

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.