1,221
社区成员
发帖
与我相关
我的任务
分享
#include <tlhelp32.hpp>
bool CrnProcessExists(String strFileName)
{
String strExeFile;
bool bExists(false);
DWORD dwSize;
PROCESSENTRY32 pe32 = { sizeof(pe32) };
MODULEENTRY32 me32 = { sizeof(me32) };
HANDLE hSnapShot, hModuleSnap;
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hSnapShot == NULL)
return false;
bool bFlag = Process32First(hSnapShot, &pe32);
while(bFlag)
{
strExeFile = String(pe32.szExeFile);
if(strExeFile.Pos("\\") == 0)
{
hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, pe32.th32ProcessID);
if(hModuleSnap == INVALID_HANDLE_VALUE)
strExeFile = String(pe32.szExeFile);
else
{
if(Module32First(hModuleSnap, &me32))
strExeFile = String(me32.szExePath);
}
CloseHandle(hModuleSnap);
}
if(strExeFile.UpperCase() == strFileName.UpperCase())
{
bExists = true;
break;
}
bFlag = Process32Next(hSnapShot, &pe32);
}
CloseHandle(hSnapShot);
return bExists;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
bool bExists = CrnProcessExists("E:\\Tencent\\QQ2007\\QQ.exe");
ShowMessage(String("QQ进程") + (bExists? "找到了": "没找到"));
}