Created By  inflectra.adam Thursday, April 25, 2013

If you use the Global.DoLaunch(...) command to launch a Windows console application, it will return a process ID. This article provides some sample code for executing a console application and checking to make sure that the process is not still running.

function IsProcessRunning(pid)
        var strComputer = ".";
        var SWBemlocator = new ActiveXObject("WbemScripting.SWbemLocator");
        var objWMIService = SWBemlocator.ConnectServer(strComputer, "/root/CIMV2");
        var strProcess;
        var query = "Select * from Win32_Process";
            query+=" WHERE Handle="+pid;
        var colItems = objWMIService.ExecQuery(query);
        var e = new Enumerator(colItems);
        for(; ! e.atEnd(); e.moveNext())
            if(pid) return true;
        if(pid) return false;
    Log("PID: "+Global.lastPid+" Running: "+IsProcessRunning(Global.lastPid));

Article Info
  • Last Updated: 4/25/2013
  • Article ID: KB47
  • Views: 2994