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

#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

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

posted @ 2012-08-07 10:08  upendi  Views(336)  Comments(0Edit  收藏  举报