>How to Create Dos Environment Variables from vfp...
>
>(variables which we create in dos with set command...)
In what context? Modifying the environment values of the parent process for VFP is extremely difficult, it involves getting a handle to memory not normally shared by the parent process and modifying the content, which leads to all sorts of interesting problems in accessing and permissions, and is best approached in another language than VFP. Setting the VFP process' environment variable values requires a Win32 API call, SetEnvironmentVariable(), declared in VFP as:
DECLARE INTEGER SetEnvironmentVariable IN WIN32API, ;
STRING lpName, ;
STRING lpValue
The name of the environment variable is passed as lpName, and the value to be set as lpValue; both should be explicitly null terminated, as shown below:
DECLARE INTEGER SetEnvironmentVariable IN WIN32API, ;
STRING lpName, ;
STRING lpValue
cEnvName = "FOO" + CHR(0)
cEnvValue = "BAR" +CHR(0)
IF SetEnvironmentVariable(cEnvName, cEnvValue) # 0
ELSE
ENDIF
Once set in the current process, the environment variables are inherited by any child processes spawned by the current process (ie programs started with the VFP RUN command, or started via CreateProcess(), ShellExecute() and the like.)
You can also define a custom environment block to be inherited by child processes spawned with CreateProcess(); the
lpEnvironment parameter of CreateProcess() can be either NULL, in which case the current environment values are inherited by the child process, or can be a pointer to a new environment block, which contains a null terminated list of null terminated environment values (the last environment string defined is followed by two null characters rather than one.) If a custom environment block is defined, it completely replaces the current environment block for the child; nothing is inherited except as explicitly set in the environment block, which can create problesm if you make assumptions about inherited paths and the like. The code in my API_APPRUN class could be modified pretty easily to pass a custom environment block.
See the MSDN docs on CreateProcess for greater detail here; they're very explicit about the format.