+ 3

How to allow one instance of exe

Hi I have an application which need to have only one instance of the application active at a time. What to do when we have to restrict one instance of exe is active?

14th Feb 2025, 5:57 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
8 Answers
+ 4
I have done this in Windows via system API calls to get the list of running windows and see if your window title is in the list. I always felt that it needed to be more reliable than using the Title property, but it was the best idea I could find. It solved the problem and there were no reports that indicated otherwise.
14th Feb 2025, 11:16 PM
Brian
Brian - avatar
+ 2
Use a named mutex with some unique name then check for the enum ERROR_ALREADY_EXISTS I can't remember how the code implementation looks like but I've tried it before on Qt and it works well
21st Feb 2025, 9:47 AM
Badgirl MIRI
Badgirl MIRI - avatar
+ 1
Thanks Bob_Li and Brian Yeah, I too had an idea of title , but it is too initial thought . More than this, is there a way to achieve this as platform independently (both linux and windows ) ?
15th Feb 2025, 1:54 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
I was also wondering about that, but it's os specific, it seems.
15th Feb 2025, 2:20 PM
Bob_Li
Bob_Li - avatar
0
21st Feb 2025, 10:21 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Thanks venom85jojes Does python one is platform independent? If proc.info is having extension as .exe for name, will linux also has .exe extension? Regarding last method, singleton class is limited to one application. Right? Or is it singleton across the os and user level ?
24th Feb 2025, 12:14 PM
Ketan Lalcheta
Ketan Lalcheta - avatar