Forum Discussion

jsr_78's avatar
jsr_78
Occasional Contributor
13 years ago

Find the process

Hi,



Can you please help me how to find the right process when I have 3 instance of same process?

 

e.g. I have 3 process that are running with same name "MSIEXEC" and i can i differentiate them only with  one of the strings in "CommandLine" property.



Can you please help me to loop around 3 process to find the right one?



Thanks,

Srinivas

2 Replies

  • Hi Srinivasa,



    When the installation starts, there are several processes having the same "msiexec" name, and the process taken by TestComplete may not contain the needed window, so TC maps the process anew (adds the 1 index to the process name). To avoid the problem, you can modify the NameMapping scheme and specify the required children for the needed process. See the "Specifying Child Objects Required for Mapped Object Identification" help topic for details. Also, you need to avoid using the Index property for mapping the installation's main form and add the Visible property, which equals True, to the mapping criteria. Please note that the value of the Caption property for the main form can change. You can use wildcards to make your NameMapping scheme more reliable.
  • Mykola_Kushnir's avatar
    Mykola_Kushnir
    Occasional Contributor
    Look at code snippet below:



    function ProcessSearchTest()

    {

      var processName = "msiexec";

      var processCommandLine = "MSIEXEC  /help";

     

      var objProcess = FindProcessByCommandLine(processName, processCommandLine);

    }



    function FindProcessByCommandLine(processName, commandLine)

    {

      var commandLineProcess = null;

      var arrProcesses = GetProcessByName(processName);

       

      for (var i = 0; i < arrProcesses.length; i++)

      {

        if (arrProcesses.CommandLine == commandLine)

        {

           commandLineProcess = arrProcesses;

           break;

        }        

      }

     

      if (commandLineProcess == null)

      {

        Log.Message("Process with specified command line - " + commandLine + " not found.");

      }

       

      return commandLineProcess;

    }



    function GetProcessByName(prName)

    {

      Log.AppendFolder("GetProcessByName");

     

      var p = null;  

      var arrProcesses = [];

     

      for (var i = 0; i < Sys.ChildCount; i++)

      {  

        p = Sys.Child(i);

        if (aqString.ToLower(p.ProcessName) == aqString.ToLower(prName))

        {

          arrProcesses.push(p);   

        }

      }



      if (arrProcesses.length == 0)

      {

        Log.Message(prName + " process not found.");

      }

      else

      {

        Log.Message("found '" + arrProcesses.length + "' process(es).");

      }

     

      Log.PopLogFolder();

     

      return arrProcesses;  

    }