C++Builder写的,你看看先,对有的进程可能还要设置权限才能杀掉
HANDLE m_SnapShot,hProcess;
PROCESSENTRY32 Ppe;
bool FindProc;
unsigned long pid;
Ppe.dwSize = sizeof(Ppe);
m_SnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (m_SnapShot == INVALID_HANDLE_VALUE)
{
ShowMessage("error");
}
FindProc = Process32First(m_SnapShot,&Ppe);
while (FindProc)
{
//ShowMessage(Ppe.szExeFile);
if (stricmp(Ppe.szExeFile,Edit1->Text.c_str()) == 0)
{
pid = Ppe.th32ProcessID;
ShowMessage("Find proc,pid = " + FloatToStr(Ppe.th32ProcessID));
break;
}
FindProc = Process32Next(m_SnapShot,&Ppe);
}
if((hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid)) == NULL)
{
ShowMessage("open proc error");
return ;
}
TerminateProcess(hProcess, 0xffffffff);
CloseHandle(hProcess);