5

Is there a way I can force an application on Windows to be a single-instance application, i.e., not launch if another instance of the same application is already running? Ideally, I want to be able to do this without needing to replace the actual application with a stub, but I would not mind using one if really necessary.

  • The reason why it is so hard is because you are essentially modifying the Application's memory, without changing its logic. It is like if someone came into your house and rearranged all your furniture and you came in and just collapse where you thought your bed was. . . At best, the application will churn along like nothing happened. At worst, you get silent data corruption. IMO, neither are worth the time. – surfasb Jul 29 '11 at 19:06
5

normally you have to implement that "singleton" feature right into the application. if you want to guard it "from the outside", you have to use a wrapper which checks, if you have another instance running already. there might be more solutions to this but i once did the trick with nsis. the idea is this:

  • Pretty much what I was afraid of. Is there an easy way to create a "generic" wrapper? From the docs, it seems that every wrapper instance will share the same ID, which means I will need to build one wrapper per application. – Soumya Jul 29 '11 at 10:42
  • you could use nsis.sourceforge.net/… as the base for such a generic wrapper. see ${processName}. but thats the same as just monitoring all processes and check, if there is already a binary running pointing to yourapplication.exe. why do you need such singleton-thing for all the apps anyway? – akira Jul 29 '11 at 11:17
  • Not all, but multiple. Especially ones that launch from keyboard shortcuts. I recently killed Windows by accidentally launching about a hundred copies of Task Manager. – Soumya Jul 29 '11 at 11:38
  • switch to win7 :) – akira Jul 29 '11 at 11:43
  • Recommend building the checks into the program itself i.e. Akira's description of the normal way. Otherwise, risk people pinning the app to the quick launch panel, bypassing the fake wrapper installer. An ideal solution would be for this to be configurable from Windows, so that the app could specify whether it should be the sole instance, and also an admin. can specify whether it should be the sole instance by registration. Similar to how a file ext. is registered to have an icon, a default program and a list of rec. apps. I'd be interested to hear other people's opinions too. – Knickerless-Noggins Aug 25 '17 at 10:26
2

Unless there is a workaround you can apply with the Application Compatibility Kit that enables this – which I doubt (it isn't the kind of thing that itself breaks compatibility1) – then there is no setting in Windows.

Other than a launcher application the other approach would be to monitor for new processes (eg. WMI instance creation events for Win32_Process objects – filtered by session of course) and perform some action to block the second instance.


1 Of course a fix might be needed where an application uses an unsupported mechanism to detect multiple instances of itself so the detection mechanism needs a shim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.