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
Announcement
Collapse
No announcement yet.
Detecting if an app is already started
Collapse
X
-
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:
-
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:
-
Originally posted by William Burns View Post...didn't see the Is_Already_Running function...
I see that function now....
As far as I can tell, the function itself is intact and should work.
Leave a comment:
-
another instance of it is already running
If that is a concern, open a common file.
There are many links on this subject.
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 *
Leave a comment:
-
Originally posted by Chris Burgess View PostHi 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.
===========================
"First they ignore you,
then they laugh at you,
then they fight you,
then you win."
Mahatma Gandhi (1869-1948)
===========================
Leave a comment:
-
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
Leave a comment:
-
Check out my MP3 player in the source forum:
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:
-
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.
Leave a comment: