typedef enum
{
E_RET_SUCCESS,
E_RET_FAILED
}eRet;
eRet
KillProcess(WCHAR *prcName)
{
BOOL isSucceed = FALSE;
HANDLE hd = NULL;
PROCESSENTRY32 procEntry32;
hd = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hd == INVALID_HANDLE_VALUE)
{
return E_RET_FAILED;
}
procEntry32.dwSize = sizeof(PROCESSENTRY32);
isSucceed = Process32First(hd, &procEntry32);
if (isSucceed == FALSE)
{
CloseHandle(hd);
hd = NULL;
return E_RET_FAILED;
}
while (isSucceed)
{
if (wcscmp(procEntry32.szExeFile, prcName) == 0)
{
break;
}
isSucceed = Process32Next(hd, &procEntry32);
}
CloseToolhelp32Snapshot(hd);
hd = NULL;
if(isSucceed)
{
hd = OpenProcess(PROCESS_TERMINATE, FALSE, procEntry32.th32ProcessID);
if (hd == NULL)
{
return E_RET_FAILED;
}
isSucceed = TerminateProcess(hd, 0);
CloseHandle(hd);
hd = NULL;
if (isSucceed == 0)
{
return E_RET_FAILED;
}
}
return E_RET_SUCCESS;
}