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.
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:
- create a "fake installer" which itself is only a little wrapper around the app you want to start
- make that installer a singleton, see here http://nsis.sourceforge.net/Allow_only_one_installer_instance or http://nsis.sourceforge.net/Check_whether_your_application_is_running
- launch your app from that "wrapper installer", see here http://nsis.sourceforge.net/ExecCmd_plug-in
- "hide" the normal application icon from the user and present that fake-installer. since you can add a nice looking icon to it, you should be able to make it look like the original program.
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.