用C查看系统任务管理器中运行的程序

来源:互联网 发布:货物找车软件 编辑:程序博客网 时间:2024/05/29 08:45
#include <stdio.h>#include <windows.h>#include <tlhelp32.h>void main(void){        PROCESSENTRY32 pe32;        pe32.dwSize = sizeof(pe32);        HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);        if(hProcessSnap == INVALID_HANDLE_VALUE)        {            printf("CreateToolhelp32Snapshot调用失败!\n");            return ;        }        BOOL bMore = ::Process32First(hProcessSnap,&pe32);        while(bMore)        {            printf("进程ID号:%u\t\t",pe32.th32ProcessID);            printf("进程名称:%s\n",pe32.szExeFile);            bMore = ::Process32Next(hProcessSnap,&pe32);        }        ::CloseHandle(hProcessSnap);        return;}


1. 注意头文件的顺序。。。
2. 初始化结构体大小
3. 最后要关闭handle

能这样得到系统正在运行程序的数据,就可以写成文件,然后传送出去。。。你懂得!