枚举windows进程
?將當(dāng)前運(yùn)行的進(jìn)程列舉出來(C++ Code):
?
#include<windows.h>
#include<tlhelp32.h>
//#include <iomanip>
#include<iostream>
using namespace std;
int main()
{
??? int count=0;
??? PROCESSENTRY32 pe32;
??? //使用這個(gè)數(shù)據(jù)之前設(shè)置大小
??? pe32.dwSize=sizeof(pe32);
??? HANDLE hProcessSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
??? if(hProcessSnap==INVALID_HANDLE_VALUE)
??? {
??????? cout<<"CreateToolhelp32Snapshot調(diào)用失敗!"<<endl;
??????? return -1;
??? }
??? //遍歷進(jìn)程快照,輪流顯示每個(gè)進(jìn)程信息
??? BOOL bMore=::Process32First(hProcessSnap,&pe32);
??? cout<<"進(jìn)程名稱/t/t/t/t/t進(jìn)程ID號(hào)"<<endl;
??? while(bMore)
??? { 
??//stricmp():比較字符串時(shí)忽略大小寫;strcmp:比較字符串時(shí),不會(huì)忽略大小寫
??if(stricmp(pe32.szExeFile, "QQ.exe") == 0)?//判斷當(dāng)前進(jìn)程名是不是QQ.exe
???cout<<"Find the process-QQ.exe, PID="<<pe32.th32ProcessID<<endl;
??????? //cout<<pe32.szExeFile<<"/t/t/t/t/t"<<pe32.th32ProcessID<<endl;??//輸出進(jìn)程名和進(jìn)程ID
??????? count++;
??????? bMore=::Process32Next(hProcessSnap,&pe32);
??? }
??? cout<<"當(dāng)前運(yùn)行進(jìn)程總數(shù)為:"<<count<<endl;
??? ::CloseHandle(hProcessSnap);
??? return 0;
}
?
總結(jié)
以上是生活随笔為你收集整理的枚举windows进程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: javaERP跨境电商平台,跨境电商源码
- 下一篇: 基于间隔推送全量更新数据状态的设计方法
