Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Create Environment Variables
Message
From
15/01/1999 00:47:27
 
 
To
14/01/1999 10:20:03
Vinod Parwani
United Creations L.L.C.
Ad-Dulayl, Jordan
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00175925
Message ID:
00176337
Views:
23
>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
   *  it worked
ELSE
   * it didn't, and the error is extracted with GetLastError()
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.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform