Applies to TestComplete 14.20, last modified on September 11, 2019

Description

The WMI.GetEnvironmentVariable method lets you get the value of an environment variable specified by its name. The method retrieves the variable value on the computer specified by the WMI.ComputerName property, which can be either a local or remote computer.

Declaration

WMI.GetEnvironmentVariable(Name)

Name [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Name

The variable name, for example, Path. The name is case-insensitive.

Result Value

A string that holds the variable value.

Remarks

  • Note that you can also obtain environment variable values for the local computer using the aqEnvironment.GetEnvironmentVariable method.

  • The 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 WMI.GetEnvironmentVariable method returns the value of the system-specific variable. To get the value of the user-specific variable, use the aqEnvironment.GetEnvironmentVariable method.

Example

The following example demonstrates how you can obtain the path to the Windows directory on a local computer:

JavaScript, JScript

function Test1()
{
  WMI.ComputerName = ".";
  Log.Message (WMI.GetEnvironmentVariable("windir"));
}

Python

def Test1():
  WMI.ComputerName = "."
  Log.Message (WMI.GetEnvironmentVariable("windir"))

VBScript

Sub Test1
  WMI.ComputerName = "."
  Log.Message WMI.GetEnvironmentVariable("windir")
End Sub

DelphiScript

procedure Test1;
begin
  WMI.ComputerName := '.';
  Log.Message (WMI.GetEnvironmentVariable('windir'));
end;

C++Script, C#Script

function Test1()
{
  WMI["ComputerName"] = ".";
  Log["Message"](WMI["GetEnvironmentVariable"]("windir"));
}

See Also

WMI.ComputerName Property
WMI.PostEnvironmentVariableInfo Method
aqEnvironment.GetEnvironmentVariable Method

Highlight search results