判断某个进程是否在进程管理器中 - C++ Builder / Windows SDK/API
已知某个进程XXX.EXE,程序没有它往下运行不了,所以先判断,这个进程是否已经运行,也就是在进程管理器中了
[解决办法]
#include "tlhelp32.hpp"bool __fastcall CrnFindProcess(String strExeFile){ String strFileName; char szBuf[256]; bool bFound(false); PROCESSENTRY32 pe32 = {sizeof(pe32)}; HANDLE hSnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapShot == NULL) return bFound; try { bool bFlag = ::Process32First(hSnapShot, &pe32); while (bFlag) { strFileName = String(pe32.szExeFile); if (strFileName.Pos("\\") != 0) strFileName = ExtractFileName(strFileName); if (SameText(strFileName, strExeFile)) { bFound = true; break; } bFlag = ::Process32Next(hSnapShot, &pe32); } } __finally { ::CloseHandle(hSnapShot); } return bFound;}//---------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender){ ShowMessage(CrnFindProcess("QQ.exe")? "指定进程找到了": "未找到进程");}