×
Namespaces

Variants
Actions

How to check whether the application is running

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: kavitaobhan (19 Nov 2007)
Last edited: hamishwillee (06 Feb 2012)


Description.

Some time we need to findout whether some application/exe is running or not (specially if we want to launch them, if not running). The static class MySystemUtils contain two functions to check whether application/exe is running or not. The function IsApplicationRunningL() check whether application is running or not. TApaTask::FindApp( aApplicationUid ) doing job for IsApplicationRunningL() to find application is running or not, but fortunately FindApp() works for only Apps not for exe's, so need to write another function to find out whether exe is running or not.


Header Required:

#include <apacmdln.h>  
#include <apgcli.h>
#include <apgtask.h>
#include <e32std.h>
#include <w32std.h>

Library Needed:

LIBRARY  ws32.lib apgrfx.lib euser.lib

Header File MySystemUtils.h

class MySystemUtils
{
 
/**
* Description : Function to check
whether the applicaton is running.
* Params  : UID of the application to be checked
* Returns  : true if the application is running
*/

static TBool IsApplicationRunningL( const TUid& aApplicationUid );
 
/**
* Description : Function to check if the executable is
running or not
* Params  : Descriptor containing name of Exe
* Returns  : true if running
* Comments  : format exename*
*/

static TBool IsExeRunning( const TDesC& aExeName );
 
 
};

Source code MySystemUtils.cpp

#include <MySystemUtils.h>
 
//Checking Whether the Application is Running
TBool MySystemUtils::IsApplicationRunningL( const TUid& aApplicationUid )
{
RWsSession windowSession;
User::LeaveIfError( windowSession.Connect() );
 
TApaTaskList apataskList( windowSession);
TApaTask apatask = apataskList.FindApp( aApplicationUid );
 
TBool situationFlag = apatask.Exists();
 
// Close window server session
windowSession.Close();
 
return situationFlag;
}
 
// Checking Whether the Exe is Running
TBool MySystemUtils::IsExeRunning( const TDesC& aExeName )
{
//make sure that the name of executable is without extension. i.e helloworld not helloworld.exe
TFileName executableName;
executableName.Copy( aExeName );
executableName.Trim();
executableName.Append(_L("*"));
 
TBool situationFlag = EFalse;
TFindProcess processSearch;
TFullName processFullName;
while( processSearch.Next( processFullName ) == KErrNone)
{
 
if( processFullName.Match(executableName) != KErrNotFound )
{
return ETrue;
}
}
return situationFlag;
}

How to use it ???

//you can call static method in your AppView/AppUI directly as follows.
if(MySystemUtils::IsExeRunning(KMyExeName))
{
//do your task
}

Related Links:

This page was last modified on 6 February 2012, at 06:32.
45 page views in the last 30 days.
×