VC:杀死进程
时间:2011-03-09 来源:yangyh
BOOL KillProcessFromName(LPCSTR lpProcessName)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
if(!Process32First(hSnapShot,&pe))
{
return FALSE;
}
string strProcessName = lpProcessName;
// strProcessName.MakeLower();
while (Process32Next(hSnapShot,&pe))
{
string scTmp = pe.szExeFile;
// scTmp.MakeLower();
if(scTmp==strProcessName)
{
DWORD dwProcessID = pe.th32ProcessID;
HANDLE hProcess = ::OpenProcess(PROCESS_TERMINATE,FALSE,dwProcessID);
::TerminateProcess(hProcess,0);
CloseHandle(hProcess);
return TRUE;
}
// scTmp.ReleaseBuffer();
}
//strProcessName.ReleaseBuffer();
return FALSE;
}
相关阅读 更多 +