|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
There are lots of ways to do this:
http://www.chez.com/mooncoder/Articles/MultipleIns.htm Go ahead and pick one! |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Windows Processes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|