遍历运行中进程:
BOOL IsProcessExit(wstring strFileName)
{
HANDLE hProcessSnap = NULL;
BOOL bRet = FALSE;
do
{
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
break;
}
PROCESSENTRY32 pe32 = { 0 };
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32))
{
do
{
if (_wcsicmp(pe32.szExeFile, strFileName.c_str()) == 0)
{
bRet = TRUE;
break;
}
} while (Process32Next(hProcessSnap, &pe32));
}
} while (FALSE);
if (hProcessSnap != NULL)
{
CloseHandle(hProcessSnap);
}
return bRet;
}
如果有重定向问题可以参考:重定向解决