Results 1 to 5 of 5

Thread: another instance of program is running?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    another instance of program is running?

    How to catch if another instance of the program is running?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The usual way in Win32 is to have the program create a named global semaphore/mutex/whatever first thing. They can be queried for. If it already exists, the app is already running.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Here is an example:

    Code:
    HANDLE		g_hMutex;
    	//Create A Mutex
    	g_hMutex = CreateMutex( NULL, TRUE, "Program Name");	//Create A Mutex To Keep The Program From Running More Than Once
    	if (g_hMutex && (GetLastError() == ERROR_ALREADY_EXISTS ))
    		return 0;
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    another instance of program is running?

    Thanks a lot

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    If the problem is that you don't want more then one instance of your app to run. Then you should google on Singelton classes. It's a verey common way to just make one instance of an app run.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width