BOOL suspend_or_resume_process_thread(DWORD pid, BOOL suspend) {
BOOL r = FALSE;
HANDLE snapshot;
THREADENTRY32 thread_entry;
HANDLE thread;
snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
thread_entry.dwSize = sizeof(thread_entry);
if (Thread32First(snapshot, &thread_entry) == FALSE) {
CloseHandle(snapshot);
return FALSE;
}
do {
if (thread_entry.th32OwnerProcessID != pid)
continue;
thread =
OpenThread(THREAD_SUSPEND_RESUME, FALSE, thread_entry.th32ThreadID);
if (thread == NULL)
continue;
if (suspend)
SuspendThread(thread);
else
ResumeThread(thread);
CloseHandle(thread);
} while (Thread32Next(snapshot, &thread_entry));
CloseHandle(snapshot);
return r;
}
挂起和恢复进程
由
·
发表回复