Announcement

Collapse
No announcement yet.

Detecting if an app is already started

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • John Petty
    replied
    Kev
    Interesting approach, current version requires 2000 server or 2000 Pro or above. Without diverting the thread, those who try to protect their code with packers etc might want to look at this function in the same toolbox Toolhelp32ReadProcessMemory Function.
    John

    Leave a comment:


  • Kev Peel
    replied
    If you need to find out who is running or how many instances of you program are running on the system, see my post in the following thread:

    User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.


    The above code will enumerate all processes, simply a case of comparing the process executable using a FindFirstFile() comparison. I use similar code to enumerate all running instances and shut the others down if an auto-update is imminent (the user is prompted about this first). It won't be able to detect others running the app from another computer (ie. on a network share), so I recommend the user against that.

    PS. Weirdly, the forum search here turned up nothing for "CreateToolhelp32Snapshot" (all posts, all forums), but I found the title in POFFS and used that.

    Leave a comment:


  • John Petty
    replied
    As Mike said could still be running on a network station, nor would the simpe mutex described detect if it is running in another terminal services or Citrix session

    Leave a comment:


  • Mel Bishop
    replied
    Originally posted by William Burns View Post
    ...didn't see the Is_Already_Running function...

    I see that function now....
    The source got scrambled during the transition from the old board to the new. Stuff happens you know.

    As far as I can tell, the function itself is intact and should work.

    Leave a comment:


  • Mike Doty
    replied
    another instance of it is already running
    Note: It could still be running on another station.
    If that is a concern, open a common file.

    There are many links on this subject.

    PowerBASIC and related source code. Please do not post questions or discussions, just source code.

    User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.


    http://www.powerbasic.com/support/pb...ad.php?t=22702 *
    Last edited by Mike Doty; 1 May 2009, 03:35 PM. Reason: * My solution by recording logons

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Chris Burgess View Post
    Hi all,
    Can anyone tell us a way for an app to detect (when it's first launched) that another instance of it is already running, and if it is, to terminate itself?

    For example, if "MyPBApp.exe" is already running and the user doubleclicks the icon again, have the second launch of it detect this and exit, maybe with a messagebox reminding the user that doing this is a no-no.

    I'm using PBWin 8.

    Thanks in advance to anyone that can help with this one.
    Do a search for "MUTEX" which is used to check if an app is already running. There are quite a few examples in the forums. Not at all difficult to use.

    ===========================
    "First they ignore you,
    then they laugh at you,
    then they fight you,
    then you win."
    Mahatma Gandhi (1869-1948)
    ===========================

    Leave a comment:


  • William Burns
    replied
    Mel, I don't know if something happened to cut off part of the source code you referenced, or not, but I didn't see the Is_Already_Running function. So I don't know if it is using this method or not.

    But a common method to do this is to create a mutex which is a system wide placeholder that your program can use to know if it is already running.

    Here is a simple example:

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    
    Function PBMain()
       Local zName    As Asciiz * %MAX_PATH
    
       zName = "MyUniqueNameForThisProgram"
       If CreateMutex(ByVal 0, 1, zName) Then
          If GetLastError() = %ERROR_ALREADY_EXISTS Then
             MsgBox "already started... aborting",,"Already started"
          Else  
             'not already running so continue processing
             ShowDIALOG1 %HWND_DESKTOP
          End If
       Else
          MsgBox "CreateMutex failed",,zName
       End If
    END FUNCTION
    [Added later: I see that function now. Looks like some formatting issues when you pasted it because the function line is remarked out]

    Leave a comment:


  • Mel Bishop
    replied
    Check out my MP3 player in the source forum:

    PowerBASIC and related source code. Please do not post questions or discussions, just source code.


    Specifically, the Is_Already_Running function. Does exactly what you want.

    I didn't write that particular function. Got it off the forum somewhere and I can't remember the original author. Sorry.

    Leave a comment:


  • Chris Burgess
    started a topic Detecting if an app is already started

    Detecting if an app is already started

    Hi all,
    Can anyone tell us a way for an app to detect (when it's first launched) that another instance of it is already running, and if it is, to terminate itself?

    For example, if "MyPBApp.exe" is already running and the user doubleclicks the icon again, have the second launch of it detect this and exit, maybe with a messagebox reminding the user that doing this is a no-no.

    I'm using PBWin 8.

    Thanks in advance to anyone that can help with this one.
Working...
X