Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Desktop

Article Executing a process and checking if it's still running

by Adam S on 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";
        if(pid)
        {
            query+=" WHERE Handle="+pid;
        }
        var colItems = objWMIService.ExecQuery(query);
   
        var e = new Enumerator(colItems);
        for(; ! e.atEnd(); e.moveNext())
        {
            Log(e.item().Handle+":"+e.item().Name);
            if(pid) return true;
        }
       
        if(pid) return false;
    }
   
    Global.DoLaunch('iexplore.exe');
    Log("PID: "+Global.lastPid+" Running: "+IsProcessRunning(Global.lastPid));

Attachments
Article Info
Last Updated: 4/25/2013
Article ID: KB47
# Views: 1536
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.