WMI.ConnectToComputer Method

Applies to TestComplete 15.64, last modified on May 16, 2024

Description

The WMI.ConnectToComputer method connects to the WMI services on the local or remote computer. It also lets you specify the user account to use when connecting to a remote computer. To establish remote WMI connection using the current user account, you can either leave the appropriate parameters blank or connect using the WMI.ComputerName property instead.

Declaration

WMI.ConnectToComputer(Computer, User, Password)

Computer [in]    Required    String    
User [in]    Required    String    
Password [in]    Required    String    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Computer

The name or IP address of the computer to whose WMI services you want to connect. For example, "jsmith" or "192.168.1.42". Dot (".") means the local computer.

User and Password

The user name and password that will be used to connect to WMI on the remote computer. To specify the domain name along with the user name, use the DomainName\UserName format. To connect using the current user account, specify either empty strings or null values (Null in VBScript, null in JavaScript, JScript, C++Script and C#Script, None in Python and nil in DelphiScript) as the parameter values.

Note: When connecting to WMI on the local computer, these parameters must be either empty strings or null values.

Result Value

None.

Remarks

The method attempts to connects to the "root\cimv2" namespace on the target computer.

Note that the method only performs a single attempt to connect to the target computer. In case the connection cannot be established the method posts an error message to the test log. To perform multiple connection attempts during a specific timeout period, use the WMI.WaitForComputer method instead.

The method has the following parameters:

Example

The following example demonstrates how to connect to the WMI service on a local computer and post different information about the computer to the log.

JavaScript, JScript

function Test()
{
  // Specifies the local computer using the ComputerName property
  WMI.ComputerName = ".";

  // Using the ConnectToComputer method
  // WMI.ConnectToComputer(".", "", "");


  // Using the WaitForComputer method
  // WMI.WaitForComputer(".", "", "", 1000000);

  // Posts different information about the computer to the log
  WMI.PostProcessorInfo();
  WMI.PostDrivesInfo();
  WMI.PostInstalledAppsInfo();
  WMI.PostEnvironmentVariableInfo();
  WMI.MaxEventCount = 5;
  WMI.PostEventsInfo();
}

Python

def Test1():
  # Specifies the local computer using the ComputerName property
  WMI.ComputerName = "."

  # Using the ConnectToComputer method
  #WMI.ConnectToComputer(".", "", "");

  # Using the WaitForComputer method
  #WMI.WaitForComputer(".", "", "", 1000000);

  # Posts different information about the computer to the log
  WMI.PostProcessorInfo();
  WMI.PostDrivesInfo();
  WMI.PostInstalledAppsInfo();
  WMI.PostEnvironmentVariableInfo();
  WMI.MaxEventCount = 5;
  WMI.PostEventsInfo();

VBScript

Sub Test
  ' Specifies the local computer using the ComputerName property
  WMI.ComputerName = "."

  ' Using the ConnectToComputer method
  ' Call WMI.ConnectToComputer(".", "", "")


  ' Using the WaitForComputer method
  ' Call WMI.WaitForComputer(".", "", "", 1000000)

  ' Posts different information about the computer to the log
  Call WMI.PostProcessorInfo
  Call WMI.PostDrivesInfo
  Call WMI.PostInstalledAppsInfo
  Call WMI.PostEnvironmentVariableInfo
  WMI.MaxEventCount = 5
  Call WMI.PostEventsInfo
End Sub

DelphiScript

procedure Test;
begin
  // Specifies the local computer using the ComputerName property
  WMI.ComputerName := '.';

  // Using the ConnectToComputer method
  // WMI.ConnectToComputer('.', '', '');


  // Using the WaitForComputer method
  // WMI.WaitForComputer('.', '', '', 1000000);

  // Posts different information about the computer to the log
  WMI.PostProcessorInfo;
  WMI.PostDrivesInfo;
  WMI.PostInstalledAppsInfo;
  WMI.PostEnvironmentVariableInfo;
  WMI.MaxEventCount := 5;
  WMI.PostEventsInfo;
end;

C++Script, C#Script

function Test()
{
  // Specifies the local computer using the ComputerName property
  WMI["ComputerName"] = ".";

  // Using the ConnectToComputer method
  // WMI["ConnectToComputer"](".", "", "");


  // Using the WaitForComputer method
  // WMI["WaitForComputer"](".", "", "", 1000000);

  // Posts different information about the computer to the log
  WMI["PostProcessorInfo"]();
  WMI["PostDrivesInfo"]();
  WMI["PostInstalledAppsInfo"]();
  WMI["PostEnvironmentVariableInfo"]();
  WMI["MaxEventCount"] = 5;
  WMI["PostEventsInfo"]();
}

See Also

ComputerName Property
WaitForComputer Method
Service Property

Highlight search results