how to check running process

Discussion in 'Questions (Windows Mobile)' started by twisted, Jan 17, 2009.

  1. twisted

    twisted Member Licensed User

    is this the correct code for checking if a process is running?

    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.;)
  2. Erel

    Erel Administrator Staff Member Licensed User

    You should use:
    If procname.GetProcessHandle("myapp.exe") > 0 Then Shell(AppPath&"\another app.exe",""Else Msgbox("myapp is not running.","Error!!!",cMsgboxOK,cMsgboxNone)
  3. ohkovar

    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.
  4. Erel

    Erel Administrator Staff Member Licensed User

    As far as I remember it only works on the device.
  5. men

    men New Member Licensed User

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

    Sub Globals
    'prevInstance Check prepare
         Dim procList(0), procCount
    '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) 
    End If   
    End Sub
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice