in reply to Determining if self is already running under WinNT/2000

The most robust way to do that is with a Kernel object of some kind. For example, use a unique GUID for the name, and try creating a Mutex. The return value will tell you whether it was created, or if it opened one by that name that already existed. The latter means that another copy of your program beat you to it, and it is nicely atomic. The only race condition is that when the program quits there may be a small time when another process will see the mutex still there, before it is deleted. For user-launched applications, that is negligable.

You can use any kind of Kernal object that has a name and that is reference counted by processes rather than having a persistant existance. You can use something suitable for communicating back to the original to tell it to jump to the foreground, or open a new document, or whatnot; or just have all instances coordinate with each other.

—John

  • Comment on Re: Determining if self is already running under WinNT/2000