Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-03

Windows find out if an application already is running

8 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Stratmann

I tried system.hprevinst, but this shows always 0. If there are more copys of the program then hinstance is always the same value.

Reply by email

dmitry boyarintsev
to Rainer Stratmann

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

Reply by email

Rainer Stratmann
to dmitry boyarintsev

that works with getlasterror = error_already_exists when try to create a second mutex.
thanks!

dmitry boyarintsev wrote 13 lines
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 _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Fantomas
to Rainer Stratmann: I tried system.hprevinst, but this shows always 0. If there are more copys of the program…

Hello, Rainer!

you wrote
I 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.

Best regards, Fantomas

Reply by email

Frank Peelo
to Fantomas
Fantomas wrote 13 lines
Hello, Rainer! Sunday, March 15, 2009, 10:22:04 PM, you wrote: >I 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.

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.

Reply by email

Fantomas
to Luca Olivetti

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/

Best regards, Fantomas

Reply by email