how to check running process

twisted

Member
Licensed User
Longtime User
is this the correct code for checking if a process is running?

B4X:
procname.New1   'procname is a dzHW object
If procname.GetProcessHandle("myapp.exe") = True Then Shell(AppPath&"\another app.exe","") Else Msgbox("myapp is not running.","Error!!!",cMsgboxOK,cMsgboxNone)

thanks very much.;)
 

ohkovar

Member
Licensed User
Does this only work on a device? When I use it on my desktop, no matter what process name I send the GetProcessName(), I get 0 (zero) as a result, even though I can see in my task manager that the processes are running.
 

men

New Member
Licensed User
The following code works pretty good for me on the desktop, maybe you will find it usefull:

B4X:
 Sub Globals
    'prevInstance Check prepare
     Dim procList(0), procCount
     procName.New1 'dzHW object
     procList() = procName.GetProcesses 
     For i = 0 To ArrayLen(procList())-1
         If procList(i) = "myApp" Then procCount = procCount + 1  'counts myApp.exe running instances
     Next i
 End Sub

 Sub App_Start 
    'prevInstance Check execution
     If procCount > 1 Then 
        Msgbox("Program already running","Error",cMsgboxOK,cMsgboxHand) 
        AppClose
     End If   
 End Sub
 
Top