- lib: add Win function to suspend or resume all threads in a process

svn path=/trunk/boinc/; revision=14863
This commit is contained in:
David Anderson 2008-03-06 18:31:57 +00:00
parent 98274b2496
commit 933e1ec0be
3 changed files with 36 additions and 5 deletions

View File

@ -2007,3 +2007,9 @@ Rytis 6 Mar 2008
forum.inc forum.inc
languages/ languages/
en.po en.po
David 6 Mar 2008
- lib: add Win function to suspend or resume all threads in a process
lib
win_util.C,h

View File

@ -767,3 +767,30 @@ GetAccountSid(
return bSuccess; 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;
}

View File

@ -25,11 +25,9 @@ extern BOOL ValidateProductSuite(LPSTR SuiteName);
extern BOOL TerminateProcessById(DWORD dwProcessId); extern BOOL TerminateProcessById(DWORD dwProcessId);
extern BOOL AddAceToWindowStation(HWINSTA hwinsta, PSID psid); extern BOOL AddAceToWindowStation(HWINSTA hwinsta, PSID psid);
extern BOOL AddAceToDesktop(HDESK hdesk, PSID psid); extern BOOL AddAceToDesktop(HDESK hdesk, PSID psid);
extern BOOL GetAccountSid(
extern BOOL
GetAccountSid(
LPCTSTR SystemName, // where to lookup account LPCTSTR SystemName, // where to lookup account
LPCTSTR AccountName, // account of interest LPCTSTR AccountName, // account of interest
PSID *Sid // resultant buffer containing SID PSID *Sid // resultant buffer containing SID
); );
extern int suspend_or_resume_threads(DWORD pid, bool resume);