views:

36

answers:

3

Many Windows apps (like Skype or MSN for instance) don't let you start multiple instances, rather trying to run it a 2nd time just leaves the existing version running.

Is this typically done in some simple way - the start-menu shortcut is a 'wrapper' app around the main app - or is there some registry magic you can do to delegate the problem to Windows itself?

Specifically dealing with Win32 here (unmanaged C++) but happy to hear more general solutions as long as they are workable on Windows XP or later.

EDIT: this seems the best duplicate.

A: 

As far as i remember, there exist system-wide Mutexes. Set Mutex on first launch, if on launch already set, immediately exit.

Use CreateMutex() call an prepend the name with "Global\" should to the trick.

zerm
A: 
SigTerm
A: 

I just check to see if the process is already running: if it's not start the application, if it's already running bring the window to foreground. The check is done in the Main method.

I get the process name with System.Diagnostics.Process.GetCurrentProcess().ProcessName and check if it's already running System.Diagnostics.Process.GetProcessesByName(). If there are more than 1 processes focus the first of them and then exit.

Adrian Faciu