diff --git a/checkin_notes b/checkin_notes index 8070f72aae..961dd34c03 100644 --- a/checkin_notes +++ b/checkin_notes @@ -2007,3 +2007,9 @@ Rytis 6 Mar 2008 forum.inc languages/ en.po + +David 6 Mar 2008 + - lib: add Win function to suspend or resume all threads in a process + + lib + win_util.C,h diff --git a/lib/win_util.C b/lib/win_util.C index 5625af30a1..b58c0a21ef 100644 --- a/lib/win_util.C +++ b/lib/win_util.C @@ -767,3 +767,30 @@ GetAccountSid( return bSuccess; } +// Suspend or resume the threads in a given process. +// The only way to do this on Windows is to enumerate +// all the threads in the entire system, +// and find those belonging to the process (ugh!!) +// +int suspend_or_resume_threads(DWORD pid, bool resume) { + HANDLE threads, thread; + THREADENTRY32 te = {0}; + + threads = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); + if (threads == INVALID_HANDLE_VALUE) return -1; + + te.dwSize = sizeof(THREADENTRY32); + if (!Thread32First(threads, &te)) { + CloseHandle(threads); + return -1; + } + do { + if (te.th32OwnerProcessID == pid) { + thread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te.th32ThreadID); + resume ? ResumeThread(thread) : SuspendThread(thread); + CloseHandle(thread); + } + } while (Thread32Next(threads, &te)); + CloseHandle (threads); + return 0; +} diff --git a/lib/win_util.h b/lib/win_util.h index 08cc746171..99cd745324 100644 --- a/lib/win_util.h +++ b/lib/win_util.h @@ -25,11 +25,9 @@ extern BOOL ValidateProductSuite(LPSTR SuiteName); extern BOOL TerminateProcessById(DWORD dwProcessId); extern BOOL AddAceToWindowStation(HWINSTA hwinsta, PSID psid); extern BOOL AddAceToDesktop(HDESK hdesk, PSID psid); - -extern BOOL -GetAccountSid( +extern BOOL GetAccountSid( LPCTSTR SystemName, // where to lookup account LPCTSTR AccountName, // account of interest PSID *Sid // resultant buffer containing SID - ); - +); +extern int suspend_or_resume_threads(DWORD pid, bool resume);