让程序只能被运行一个实例
#include <windows.h>
int main(int argc, char* argv[])
{
HANDLE hEvent= CreateEvent(NULL,true,true,"init");
if (hEvent)
{
if (GetLastError()==ERROR_ALREADY_EXISTS)
{
printf("Initance is running!\n");
return 0;
}
}
printf("Hello World!\n");
Sleep(10000);
return 0;
}
int main(int argc, char* argv[])
{
HANDLE hEvent= CreateEvent(NULL,true,true,"init");
if (hEvent)
{
if (GetLastError()==ERROR_ALREADY_EXISTS)
{
printf("Initance is running!\n");
return 0;
}
}
printf("Hello World!\n");
Sleep(10000);
return 0;
}