aqEnvironment.GetEnvironmentVariable Method

Applies to TestComplete 15.63, last modified on April 23, 2024

Description

The GetEnvironmentVariable method returns the value of the operating system’s environment variable specified by its name.

Declaration

aqEnvironment.GetEnvironmentVariable(VarName, Is64bit)

VarName [in]    Required    String    
Is64bit [in]    Optional    Boolean Default value: False   
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

VarName

The name of the environment variable whose value you want to get. The name is case-insensitive and must not be enclosed in % characters.

Is64bit

Optional. This parameter is only effective if the computer is running a 64-bit version of Windows. It specifies whether to obtain the variable value from the 32-bit or 64-bit environment. If this parameter is False (default), the method returns the variable value defined in the 32-bit environment; if it is True -- the value defined in the 64-bit environment.

Result Value

A string holding the value of the specified environment variable.

If the specified environment variable is not defined, the method returns an empty string. An empty string is also returned if the method is called on a 32-bit version of Windows and the method's Is64bit parameter is set to True.

Remarks

  • TestComplete includes a number of built-in object properties that return the values of some common environment variables. These properties are listed in the Using Environment Variables in Automated Tests topic. It is recommended that you use these properties instead of retrieving the corresponding environment variable values using the aqEnvironment.GetEnvironmentVariable method.

  • To get the value of an environment variable defined on a remote computer, use the WMI.GetEnvironmentVariable method.

  • Windows operating system provides two types of environment variables: system-specific and user-specific. If a user-specific variable and a system-specific variable have the same name, the aqEnvironment.GetEnvironmentVariable method returns the value of the user-specific variable. To get the value of the system-specific variable with the same name, use the WMI.GetEnvironmentVariable method.

Example

The following example demonstrates how you can obtain the path to the Program Files folder on a 32-bit version of Windows:

JavaScript, JScript

Log.Message( aqEnvironment.GetEnvironmentVariable("ProgramFiles") );

// Result:
// C:\Program Files

Python

Log.Message(aqEnvironment.GetEnvironmentVariable("ProgramFiles"))

# Result:
# C:\Program Files

VBScript

Log.Message aqEnvironment.GetEnvironmentVariable("ProgramFiles")

' Result:
' C:\Program Files

DelphiScript

Log.Message( aqEnvironment.GetEnvironmentVariable('ProgramFiles') );

// Result:
// C:\Program Files

C++Script, C#Script

Log["Message"]( aqEnvironment["GetEnvironmentVariable"]("ProgramFiles") );

// Result:
// C:\Program Files

The example below demonstrates how to obtain the path to the 32-bit and 64-bit versions of the Program Files folder on a 64-bit version of Windows:

JavaScript, JScript

Log.Message( aqEnvironment.GetEnvironmentVariable("ProgramFiles") );
Log.Message( aqEnvironment.GetEnvironmentVariable("ProgramFiles", true) );

// Result:
// C:\Program Files (x86)
// C:\Program Files

Python

Log.Message(aqEnvironment.GetEnvironmentVariable("ProgramFiles"))
Log.Message(aqEnvironment.GetEnvironmentVariable("ProgramFiles", True))

# Result:
# C:\Program Files (x86)
# C:\Program Files

VBScript

Log.Message aqEnvironment.GetEnvironmentVariable("ProgramFiles")
Log.Message aqEnvironment.GetEnvironmentVariable("ProgramFiles", True)

' Result:
' C:\Program Files (x86)
' C:\Program Files

DelphiScript

Log.Message( aqEnvironment.GetEnvironmentVariable('ProgramFiles') );
Log.Message( aqEnvironment.GetEnvironmentVariable('ProgramFiles', true) );

// Result:
// C:\Program Files (x86)
// C:\Program Files

C++Script, C#Script

Log["Message"]( aqEnvironment["GetEnvironmentVariable"]("ProgramFiles") );
Log["Message"]( aqEnvironment["GetEnvironmentVariable"]("ProgramFiles", true) );

// Result:
// C:\Program Files (x86)
// C:\Program Files

See Also

GetEnvironmentVariable Method

Highlight search results