#include"StdAfx.h"
#include<windows.h>
#include<tlhelp32.h>
BOOL TerminateProcessFromId(DWORD dwId){
BOOL bRet=FALSE;
HANDLE hProcess=::OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwId);
if(hProcess)
bRet=::TerminateProcess(hProcess,0);
CloseHandle(hProcess);
return bRet;
}
BOOL ShowProcessIDList(){
PROCESSENTRY32 pe32;//={sizeof(pe32)};
pe32.dwSize=sizeof(pe32);
HANDLE hProcessSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap==INVALID_HANDLE_VALUE){
printf("CreatToolhelp32Snap 调用失败!/n");
return -1;
}
BOOL bMore=::Process32First(hProcessSnap,&pe32);
while(bMore){
printf("进程名称:%s/n",pe32.szExeFile);
printf("进程ID号:%d/n",pe32.th32ProcessID);
printf("父进程ID号:%d/n",pe32.th32ParentProcessID);
printf("主线程数目:%d/n/n",pe32.cntThreads);
bMore=::Process32Next(hProcessSnap,&pe32);
}
::CloseHandle(hProcessSnap);
return 0;
}
int main(int argc,char* argv[])
{
int i=-1;
DWORD dwID;
for(;;){
if(++i%3==0)
ShowProcessIDList();
printf("TerminateProcessId=");
scanf("%d",&dwID);
TerminateProcessFromId(dwID);
printf("OK!/n");
getchar();
}
}
windows编程之进程查看、删除
最新推荐文章于 2024-08-29 12:21:24 发布