我编写代码并使用 MFC。 我想检查进程是否存在。
例如:
if (myProcess.exe exists)
do something
else
do something else
我该怎么做?
谢谢
最佳答案
使用命名互斥体:
在程序的开头:
HANDLE hMutex = CreateMutex(NULL, TRUE, "Your program name");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
// Process already running.
CloseHandle(hMutex);
}
else
{
// No process running.
}
程序结束时:
if (hMutex)
{
CloseHandle(hMutex);
hMutex = NULL;
}
关于c++ - 检查进程是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967618/