Check if program is alreadi running

This is a discussion on Check if program is alreadi running within the Windows Programming forums, part of the Platform Specific Boards category; Whats the function i should look for if i wan to check if a similar program is alreadi running ? ...

  1. #1
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80

    Check if program is alreadi running

    Whats the function i should look for if i wan to check if a similar program is alreadi running ?
    ETC: i run program A, and i click A.exe again, i wan program A to auto restore instead of running another A again.
    /* Have a nice day */

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can do it pretty easily with a Mutex. Something like this should do the trick:

    Code:
      if(CreateMutex(NULL, FALSE, pClassName) && (GetLastError() == ERROR_ALREADY_EXISTS)) 
      {
    	SetForegroundWindow(FindWindow(pClassName, NULL));
    
    	// ExitProcess or whatever
      }
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory not released after running program
    By lehe in forum Linux Programming
    Replies: 21
    Last Post: 01-01-2011, 03:32 AM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 07:41 PM
  3. FAQ : running program inside program (spawn)
    By nipun in forum C Programming
    Replies: 3
    Last Post: 06-13-2004, 03:30 PM
  4. Running another program in windows
    By Mr_Jack in forum C++ Programming
    Replies: 4
    Last Post: 01-22-2004, 02:01 AM
  5. Running program
    By muffin in forum C Programming
    Replies: 5
    Last Post: 08-30-2001, 11:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21