示例#1
0
void CBOINCClientManager::KillClient() {
    ULONG                   cbBuffer = 128*1024;    // 128k initial buffer
    PVOID                   pBuffer = NULL;
    PSYSTEM_PROCESSES       pProcesses = NULL;

    if (m_hBOINCCoreProcess != NULL) {
        kill_program(m_hBOINCCoreProcess);
        return;
    }

    // Get a snapshot of the process and thread information.
    diagnostics_get_process_information(&pBuffer, &cbBuffer);

    // Lets start walking the structures to find the good stuff.
    pProcesses = (PSYSTEM_PROCESSES)pBuffer;
    do {
        if (pProcesses->ProcessId) {
            tstring strProcessName = pProcesses->ProcessName.Buffer;
            if (downcase_string(strProcessName) == tstring(_T("boinc.exe"))) {
                TerminateProcessById(pProcesses->ProcessId);
                break;
           }
        }

        // Move to the next structure if one exists
        if (!pProcesses->NextEntryDelta) {
            break;
        }
        pProcesses = (PSYSTEM_PROCESSES)(((LPBYTE)pProcesses) + pProcesses->NextEntryDelta);
    } while (pProcesses);

    // Release resources
    if (pBuffer) HeapFree(GetProcessHeap(), NULL, pBuffer);
}
BOOL TerminateProcessEx( tstring& strProcessName ) {
	unsigned int i,j;
    std::vector<BOINC_PROCESS> ps;
    std::vector<BOINC_PROCESS> tps;

    // Get a list of currently executing processes.
    diagnostics_update_process_list(ps);


    // Find our root process that we are supposed to terminate and
    //   terminate it.
	for (i=0; i < ps.size(); i++) {
		BOINC_PROCESS& p = ps[i];
        if (downcase_string(p.strProcessName) == downcase_string(strProcessName)) {
            if (TerminateProcessById(p.dwProcessId)) {
                tps.push_back(p);
            }
        }
	}


    // Terminate all child processes
	for (i=0; i < tps.size(); i++) {
		BOINC_PROCESS tp = tps[i];
	    for (j=0; j < ps.size(); j++) {
		    BOINC_PROCESS p = ps[j];
            if (tp.dwProcessId == p.dwParentProcessId) {
                if (TerminateProcessById(p.dwProcessId)) {
                    tps.push_back(p);
                }
            }
	    }
	}

    return TRUE;
}