DbgServices.LaunchApplication Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The DbgServices.LaunchApplication method launches an application as specified and allows the DbgServices object to trace all relevant application events and post them to the test log. The application may or may not belong to the list of tested applications defined in the TestedApps project item.

Declaration

DbgServices.LaunchApplication(FileName, Params, WorkFolder)

FileName [in]    Required    String    
Params [in]    Optional    String Default value: Empty string   
WorkFolder [in]    Optional    String Default value: Empty string   
Result A Process object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

FileName

The full path to the executable or batch file of the application you want to run.

Params

The command-line arguments to be passed to the application, if any.

WorkFolder

The path to the folder that will become the current one after the application is launched.

Result Value

The Process object that represents the instance of the application that the LaunchApplication method launched, if the launch was successful. If not, an empty object is returned. Use Exists to check if the returned object is a valid process.

Remarks

Note: When launching an application, the operating system displays a dialog box asking for your permission to run it. Due to certain limitations, the closing of this dialog box cannot be automated. You should close it manually, or modify User Account Control settings so that Windows does not display the dialog. See Using TestComplete With Administrator Privileges.

Example

The code below launches Notepad and then checks whether the application has started successfully.

JavaScript, JScript

function LaunchNotepad()
{
  var WinFolder = Sys.OSInfo.WindowsDirectory;
  DbgServices.LaunchApplication(WinFolder + "\notepad.exe");
  var Res = Sys.Process("notepad").Exists;
   
  // Checks whether Notepad has started successfully
  if (Res)
    Log.Message("Notepad has been started successfully.")
  else
    Log.Message("Notepad hasn't been started.");
    
}

Python

def LaunchNotepad():
  WinFolder = Sys.OSInfo.WindowsDirectory
  DbgServices.LaunchApplication(WinFolder + "\notepad.exe")
  Res = Sys.Process("notepad").Exists
  # Checks whether Notepad has started successfully
  if Res:
    Log.Message("Notepad has been started successfully.")
  else:
    Log.Message("Notepad hasn't been started.")

VBScript

Sub LaunchNotepad

  WinFolder = Sys.OSInfo.WindowsDirectory
  DbgServices.LaunchApplication(WinFolder & "\notepad.exe")
  Res = Sys.Process("notepad").Exists
   
  ' Checks whether Notepad has started successfully
  If Res Then
    Log.Message("Notepad has been started successfully.")
  Else
    Log.Message("Notepad hasn't been started.")
  End If
    
End Sub

DelphiScript

function LaunchNotepad;
var WinFolder, Res;
begin

  WinFolder := Sys.OSInfo.WindowsDirectory;
  DbgServices.LaunchApplication(WinFolder + '\notepad.exe');
  Res := Sys.Process('notepad').Exists;
   
  // Checks whether Notepad has started successfully
  if Res then
    Log.Message('Notepad has been started successfully.')
  else
    Log.Message('Notepad hasn''t been started.');
    
end;

C++Script, C#Script

function LaunchNotepad()
{
  var WinFolder = Sys["OSInfo"]["WindowsDirectory"];
  DbgServices["LaunchApplication"](WinFolder + "\notepad.exe");
  var Res = Sys["Process"]("notepad")["Exists"];
   
  // Checks whether Notepad has started successfully
  if (Res)
    Log["Message"]("Notepad has been started successfully.")
  else
    Log["Message"]("Notepad hasn't been started.");
    
}

See Also

DbgServices.LaunchTestedApplication
DbgServices.LaunchAllTestedApplications
DbgServices.AttachToProcess
TestedApp.Run
TestedApps.RunAll

Highlight search results