suspend process
-
hi all,i have a problem with suspending a process. Could someone help me? Thanks a lot!:rolleyes:
I expect we will be able to help you if you tell us what the problem is. Mike
-
hi all,i have a problem with suspending a process. Could someone help me? Thanks a lot!:rolleyes:
here are some code used to suspend a process. since I do not known the exact problem you meet, I only show it for you: BOOL WINAPI SuspendProcess(DWORD dwProcessID, BOOL bSuspend) { // 取得OpenThread函数的地址 typedef HANDLE (__stdcall *PFNOPENTHREAD)(DWORD, BOOL, DWORD); HMODULE hModule = ::GetModuleHandle("kernel32.dll"); PFNOPENTHREAD OpenThread = (PFNOPENTHREAD)::GetProcAddress(hModule, "OpenThread"); if(OpenThread == NULL) return FALSE; // 取得指定进程内的线程列表 HANDLE hSnap; hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID); if(hSnap != INVALID_HANDLE_VALUE) { // 遍历线程列表 THREADENTRY32 te = { 0 }; te.dwSize = sizeof(te); BOOL bOK = ::Thread32First(hSnap, &te); while(bOK) { if(te.th32OwnerProcessID == dwProcessID) { DWORD dwID = te.th32ThreadID; // 试图打开这个线程 HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, dwID); if(hThread != NULL) { // 暂停或者唤醒这个线程 if(bSuspend) ::SuspendThread(hThread); else ::ResumeThread(hThread); ::CloseHandle(hThread); } } bOK = ::Thread32Next(hSnap, &te); } ::CloseHandle(hSnap); } return TRUE; } I am a Chinese man, so the commentary is in Chinese. Regards