Limit a process starts only once

#include <windows.h>

// program starts only once
BOOL checkStartOnlyOne ()
{
BOOL bFlag = false; // exit program: false
// Create a mutex
HANDLE hMutex = CreateMutex (NULL, FALSE, L "fortest_abc123");
// Check the error code
if ( the GetLastError () == ERROR_ALREADY_EXISTS)
{
// If the mutex already exists and reset release mutex handle
the CloseHandle (hMutex);
hMutex = NULL;
}
the else
{
bFlag = to true;
}
return bFlag;
}

Published 18 original articles · won praise 0 · Views 5619

Guess you like

Origin blog.csdn.net/M_ZONE125/article/details/104881407