用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程 .
来源:互联网 发布:外国人在淘宝网可以吗 编辑:程序博客网 时间:2024/05/21 10:08
用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程
在很多情况下需要对系统的进程进行操作,方法有很多种但最常用的是
CreateToolhelp32Snapshot/Process32First/Process32Next 一系列API使现结束进程使用
TerminateProcess使现
下面的函数可以使现对进程的枚举:
int ProcessList()
{
PROCESSENTRY32 pe32;
pe32.dwSize=sizeof(pe32);
int count=0;
HANDLE hProcessSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap==INVALID_HANDLE_VALUE)
{
printf("CreateToolhelp32Snapshot调用失败!");
return -1;
}
BOOL bMore=::Process32First(hProcessSnap,&pe32);
printf("%20s/t%10s/n","进程名","PID");
printf("====================================/n");
while(bMore)
{
count++;
printf("%20s/t%10d/n",pe32.szExeFile,pe32.th32ProcessID);
bMore=::Process32Next(hProcessSnap,&pe32);
}
::CloseHandle(hProcessSnap);
printf("====================================/n");
printf("/n当前系统进程数为:%d/n",count);
return 0;
}
结束进程可以使用下面的函数:(使现其中dwid为想要结束的进程ID可通过列进程的函数得到)
int TerminateProcessFromId(DWORD dwId)
{
BOOL bRet=FALSE;
HANDLE hProcess=::OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwId);
if(hProcess!=NULL)
{
bRet=::TerminateProcess(hProcess,0);
}
::CloseHandle(hProcess);
if(bRet)
printf("%d 进程结束成功....../n/n/n/n",dwId);
else
printf("%d 进程结束失败....../n/n/n/n",dwId);
return 0;
}
与进程相关的操作通常还要提升权限,由关提升权限可以看偶的另一篇笔记《提升进程权限代码.》
由于代码相对比较简单,所以就没有更多的文字说明,关键的函数加了注释,其实使用时直接调用就OK了.
- 用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程
- 用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程
- 用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程
- 用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程 .
- 用CreateToolhelp32Snapshot、Process32First、Process32Next枚举进程(BCB)
- ExitProcess,TerminateProcess,CreateToolhelp32Snapshot,Process32First,Process32Next,OpenProcess
- 枚举当前系统进程--CreateToolhelp32Snapshot
- CreateToolhelp32Snapshot枚举进程
- CreateToolhelp32Snapshot枚举进程
- CreateToolhelp32Snapshot枚举进程
- CreateToolhelp32Snapshot枚举进程
- CreateToolhelp32Snapshot枚举进程
- CreateToolhelp32Snapshot枚举进程
- CreateToolhelp32Snapshot枚举进程
- CreateToolhelp32Snapshot枚举进程
- 获取系统进程 CreateToolhelp32Snapshot
- CreateToolhelp32Snapshot获取系统进程
- API枚举系统进程
- 数据结构03.1 队列模拟(数组)
- DP算法入门(3)——最大子段和
- 合并排序
- php+js+mysql设计的仿webQQ-<6>JS创建聊天窗口
- 用wsprintf格式化字符串 .
- 用CreateToolhelp32Snapshot/Process32First/Process32Next API枚举系统进程 .
- 关于java优先队列的用法
- DirectX9 SDK Samples(16) ShadowMap Sample(1)
- Antenna Impedance
- test
- C++中通过溢出覆盖虚函数指针列表执行代码
- 梦境
- Arrays的toString()方法
- lucene3.6 中文分词 文件索引