Originally Posted by
Superfreak3
It's a little widget that runs on Windows system startup to check if our Client app needs to be updated. I wouldn't worry too much about the .exe being copied and run elsewhere. The app just checks a local .ini and an .ini file on the server for versions to trigger the call to Winodws Installer packages (.msi, .msp). It runs silently - no interface.
The reason I want to make this change is for some reason, on an end users XP systems, it seems that the widget is running twice. It looks like there are duplicate entries in the .log that is created. I'm just trying to prevent this from occuring.
I was thinking that I could check to see if the .log file is open and if so, dump out.
Again, I'm no C++ guy so take it easy on me
Something from the past, I first posted it over 10 years ago....
You should just remove the messagebox bit and exit.
Your app should call CloseHandle(hMapping) when it exists.
Code:
hMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,PAGE_READONLY, 0, 32, szAppName);
if (hMapping)// Check to see if app is already running
{
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
sprintf(sBuffer,"%s is already running. Create another instance?",szAppName);
if(MessageBox(NULL, sBuffer,"Error",MB_ICONERROR| MB_YESNO)==IDNO)
{
CloseHandle(hMapping);
ExitProcess(1);
}
}
}
else
{
MessageBox(NULL, "Error creating file mapping.", "Error",MB_ICONERROR| MB_OK);
ExitProcess(1);
}
Other methods;
How do you only allow one instance of an app?