I tried system.hprevinst, but this shows always 0. If there are more copys of the program then hinstance is always the same value.
Mailing lists / fpc-pascal / 2009-03
Windows find out if an application already is running
8 messages · 6 people · –
- FFantomas 2
- RRainer Stratmann 2
- Ddmitry boyarintsev 1
- FFrank Peelo 1
- Lleledumbo 1
- LLuca Olivetti 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
it's better to use named mutexes (supported on all Windows versions) to find out if there's another instance of the app running.
do the following on application start:
- create a named mutex (constant name)
- try to lock the mutex (0 time waiting), if failed then there's another instance already running.
Thanks,
Dmitry
that works with getlasterror = error_already_exists when try to create a second mutex.
thanks!
dmitry boyarintsev wrote 13 lines
I tried system.hprevinst, but this shows always 0. If there are more copys of the program…
Hello, Rainer!
you wroteI tried system.hprevinst, but this shows always 0. If there are more copys of the program then hinstance is always the same value.
hPrevInst does not work under Win32. It is only for Win16, AFAIK. Use a named mutex, as it was given, or a named event. Also, you can find a window created by the previous instance by its class name.
Fantomas wrote 13 lines
There is a technique presented at
http://www.flounder.com/nomultiples.htm
It's not in Pascal, but the same technique should work in any language.
Is it the same technique used by
http://wiki.lazarus.freepascal.org/UniqueInstance UniqueInstance ?
En/na leledumbo ha escrit:
Is it the same technique used by http://wiki.lazarus.freepascal.org/UniqueInstance UniqueInstance ?
No, UniqueInstance uses an IpcServer/IpcClient, so it is cross-platform.
Bye
Thank you all for the useful info. In view of aforesaid named objects seem to be the simplest and the most reliable way to pevent running multiple instances af an application under Win32/
