代码如下
#include "stdafx.h" #include#include #include #include using namespace std; int KillProcess(DWORD pid){ HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pid); if (hProcess == NULL){ printf("OpenProcess errorn"); } if (TerminateProcess(hProcess, 0)){ printf("kill process successn"); return 0; } else{ printf("kill process faildn"); return 0; } CloseHandle(hProcess); } int GetProcess(){ char buff[1024] = { 0 }; PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if (hProcessSnap == INVALID_HANDLE_VALUE){ printf("CreateToolhelp32Snapshot error"); return 0; } BOOL bProcess = Process32First(hProcessSnap,&pe32); while (bProcess){ wsprintf(buff, "%s---------%drn", pe32.szExeFile, pe32.th32ProcessID); printf(buff); memset(buff, 0x00, 1024); bProcess = Process32Next(hProcessSnap, &pe32); } CloseHandle(hProcessSnap); return 0; } int _tmain(int argc, _TCHAR* argv[]) { //cout<<"Hello,world!"<



