Kbase 17125: How to Call WIN32 API Function: SetEnvironmentVariable
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
How to Call WIN32 API Function: SetEnvironmentVariable
DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.
INTRODUCTION:
=============
The following sample code shows how to call the Win32 API function
called SetEnvironmentVariable. This function allows an environment
variable's value to be set.
This code has been tested on Windows NT 4.0 Workstation only.
/*----------------------------------------------------------------*/
/* The following code will either create the environment variable */
/* or change it's value if it already exists. Please note that */
/* the changes will be for your process only, not the entire */
/* machine (on Windows NT at least). */
/*----------------------------------------------------------------*/
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
PROCEDURE SetEnvironmentVariableA EXTERNAL "KERNEL32.DLL":
DEFINE INPUT PARAMETER chrName AS CHARACTER.
DEFINE INPUT PARAMETER chrValue AS CHARACTER.
DEFINE RETURN PARAMETER intResult AS LONG.
END PROCEDURE.
RUN SetEnvironmentVariableA (INPUT "DUMMYVAR",
INPUT "SOME-VALUE",
OUTPUT intResult).
IF intResult = 1 THEN
MESSAGE "Environment Variable Has Been Changed" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "Function Failed. Not Sure Why" VIEW-AS ALERT-BOX.
Progress Software Technical Support Note # 17125