Forum Discussion

torus's avatar
torus
Contributor
3 months ago

get a list of processes with specific name

 

Is there a better way to get a list of all processes of a certain name (something that has a shorter processing time) than to loop through all processes currently running as shown in the below TC help document:

https://support.smartbear.com/testcomplete/docs/tutorials/samples/desktop/process-list.html

I was thinking it would be something like:

var myList = Sys.AllProcesses("Notepad");

  • function testmememe()
    {
      var processes = GetProcessList("taskhostw");
      var ij = 432;
    }
    
    
    function GetProcessList(processName)
    {
      var p, i;
      var processList = [];
      for (i = 0; i < Sys.ChildCount; i++)
      {
        p = Sys.Child(i);
        if( aqString.Compare(p.ProcessName, processName, false) === 0)
        {
          processList.push(p);
        }
      }
      
      return processList;
    }

    above is the code I ended up with and I guess it works pretty good. It's not too slow. Thanks.

    • torus's avatar
      torus
      Contributor

      This [Sys.Process("abc") ] will only return one of the processes. So if it had three taskhostw, I would like to get a list with three taskHostw process objects in it.

       

       

  • function testmememe()
    {
      var processes = GetProcessList("taskhostw");
      var ij = 432;
    }
    
    
    function GetProcessList(processName)
    {
      var p, i;
      var processList = [];
      for (i = 0; i < Sys.ChildCount; i++)
      {
        p = Sys.Child(i);
        if( aqString.Compare(p.ProcessName, processName, false) === 0)
        {
          processList.push(p);
        }
      }
      
      return processList;
    }

    above is the code I ended up with and I guess it works pretty good. It's not too slow. Thanks.