#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    2
    Rep Power
    0

    Question Windows Processes


    Hi does anyone know of an easy way to determine if a process already exists in a windows system??

    I am writting an app to run using the screen saver utility. The app stays active until explicitly closed. If the mouse is moved the screen saver utility will automatically kick in and start again, hence multiple copies of the app can execute, something I wish to prevent.

    Thanks!
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    There are lots of ways to do this:
    http://www.chez.com/mooncoder/Articles/MultipleIns.htm
    Go ahead and pick one!
  4. #3
  5. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    Another simple method not mentioned

    Place this code at the begining of your winmain

    Code:
    	hMapping = CreateFileMapping((HANDLE)0xffffffff, NULL, PAGE_READONLY, 0, 32, szAppName);
    
    	if (hMapping)		// Check to see if app is already running, if so exit
    	{
    		if (GetLastError() == ERROR_ALREADY_EXISTS)
    		{
    			sprintf(sBuffer,"%s is already running. Create another [YES] or exit [NO].",szAppName);
    			if(MessageBox(NULL, sBuffer, "Error",MB_ICONERROR| MB_YESNO)==IDNO)
    			        ExitProcess(1);
    		}
    	} 
    	else
    	{
    		MessageBox(NULL, "Error creating file mapping.", "Error",MB_ICONERROR| MB_OK);
    		ExitProcess(1);
    	}
    Free the HANDLE at close with

    CloseHandle(hMapping);
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo