Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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

2 Answers 2

up vote 1 down vote accepted

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:

share|improve this answer
    
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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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