Consultor Eletrônico



Kbase P143855: 4GL/ABL: How to programmatically set Windows environment variables?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   30/03/2009
Status: Unverified

GOAL:

4GL/ABL: How to programmatically set Windows environment variables?

GOAL:

How to get the value of a Windows environment variable using 4GL/ABL?

GOAL:

How to use the 'Windows Script Host object' to set and get Windows environment variables?

FACT(s) (Environment):

Windows
Progress 9.x
OpenEdge 10.x

FIX:

The following procedure gets and sets the EVTLEVEL Windows environment variable. This code may be used to set and get any Windows environment variable:

DEF VARIABLE hWshShell AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE cVariableType AS CHARACTER NO-UNDO.
DEFINE VARIABLE cVariableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cCurrentValue AS CHARACTER NO-UNDO.
DEFINE VARIABLE cDesiredValue AS CHARACTER NO-UNDO.
CREATE "WScript.Shell" hWshShell.
ASSIGN
cVariableType = "SYSTEM" /* Possible values: SYSTEM, USER, VOLATILE or PROCESS */
cVariableName = "EVTLEVEL" /* May be any Windows ENVIRONMENT variable name */
cCurrentValue = hWshShell:Environment(cVariableType):Item(cVariableName)
cDesiredValue = "none" NO-ERROR.
IF cCurrentValue NE cDesiredValue THEN
hWshShell:Environment(cVariableType):Item(cVariableName) = cDesiredValue.
RELEASE OBJECT hWshShell.