2个回答
展开全部
void CloseProcess(CString name)
{
HANDLE hProcess = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcess == INVALID_HANDLE_VALUE)
{
return;
}
PROCESSENTRY32 info = {0};
info.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hProcess, &info))
{
return;
}
BOOL bFound = FALSE;
while (1)
{
if (!Process32Next(hProcess, &info))
{
break;
}
if (info.szExeFile == name)
{
bFound = TRUE;
HANDLE hClose = ::OpenProcess(PROCESS_TERMINATE, FALSE, info.th32ProcessID);
if (hClose == NULL)
{
return;
}
if (!::TerminateProcess(hClose, 0))
{
return;
}
else
{
}
}
}
::CloseHandle(hProcess);
}
这是一个杀进程的函数。
当然,用的时候只需要输入进程名字。
中间也包括了获得进程句柄。参考下吧。
谢谢
{
HANDLE hProcess = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcess == INVALID_HANDLE_VALUE)
{
return;
}
PROCESSENTRY32 info = {0};
info.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hProcess, &info))
{
return;
}
BOOL bFound = FALSE;
while (1)
{
if (!Process32Next(hProcess, &info))
{
break;
}
if (info.szExeFile == name)
{
bFound = TRUE;
HANDLE hClose = ::OpenProcess(PROCESS_TERMINATE, FALSE, info.th32ProcessID);
if (hClose == NULL)
{
return;
}
if (!::TerminateProcess(hClose, 0))
{
return;
}
else
{
}
}
}
::CloseHandle(hProcess);
}
这是一个杀进程的函数。
当然,用的时候只需要输入进程名字。
中间也包括了获得进程句柄。参考下吧。
谢谢
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
HANDLE GetThreadHandle(HANDLE hProcess)
{
if(!hProcess)
{
return NULL;
}
DWORD dwPid = GetProcessId(hProcess);
HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwPid);
THREADENTRY32 entry;
memset(&entry, 0, sizeof(THREADENTRY32));
entry.dwSize = sizeof(THREADENTRY32);
DWORD dwThreadID = 0;
if(Thread32First(hThreadSnap, &entry))
{
if(entry.th32OwnerProcessID == dwPid)
{
dwThreadID = entry.th32ThreadID;
}else
{
while(Thread32Next(hThreadSnap, &entry))
{
if(entry.th32OwnerProcessID == dwPid)
{
dwThreadID = entry.th32ThreadID;
break;
}
}
}
}
CloseHandle(hThreadSnap);
return OpenThread(THREAD_ALL_ACCESS, FALSE, dwThreadID);
}
传入你需要查找的进程的handle,这个方法很多,在这里不做累述.
最后得到该进程中运行的线程的handle,你用完记得closehandle.
{
if(!hProcess)
{
return NULL;
}
DWORD dwPid = GetProcessId(hProcess);
HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwPid);
THREADENTRY32 entry;
memset(&entry, 0, sizeof(THREADENTRY32));
entry.dwSize = sizeof(THREADENTRY32);
DWORD dwThreadID = 0;
if(Thread32First(hThreadSnap, &entry))
{
if(entry.th32OwnerProcessID == dwPid)
{
dwThreadID = entry.th32ThreadID;
}else
{
while(Thread32Next(hThreadSnap, &entry))
{
if(entry.th32OwnerProcessID == dwPid)
{
dwThreadID = entry.th32ThreadID;
break;
}
}
}
}
CloseHandle(hThreadSnap);
return OpenThread(THREAD_ALL_ACCESS, FALSE, dwThreadID);
}
传入你需要查找的进程的handle,这个方法很多,在这里不做累述.
最后得到该进程中运行的线程的handle,你用完记得closehandle.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询