进程-取得所有系统进程可执行文件名


void FindAllProcessNames(vector<string>& outProcessesContainer )
{

PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);

HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processesSnapshot == INVALID_HANDLE_VALUE)
{
return;
}

//Process First in snapshot and traverse the list.
Process32First(processesSnapshot, &processInfo);
outProcessesContainer.push_back(processInfo.szExeFile);
while ( Process32Next(processesSnapshot, &processInfo) )
{
outProcessesContainer.push_back(processInfo.szExeFile);
}

CloseHandle(processesSnapshot);
}


应用:

#include "windows.h"
#include <string>
#include "tlhelp32.h"
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <vector>

void FindAllProcessNames(std::vector<std::string>& outProcessesContainer )
{

PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);

HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processesSnapshot == INVALID_HANDLE_VALUE)
{
return;
}

//Process First in snapshot and traverse the list.
Process32First(processesSnapshot, &processInfo);
outProcessesContainer.push_back(processInfo.szExeFile);
while ( Process32Next(processesSnapshot, &processInfo) )
{
outProcessesContainer.push_back(processInfo.szExeFile);
}

CloseHandle(processesSnapshot);
}
int _tmain(int argc, _TCHAR* argv[]){
std::vector<std::string> outProcessesContainer;
FindAllProcessNames(outProcessesContainer);
std::vector<std::string>::iterator it;
for(it = outProcessesContainer.begin();it !=outProcessesContainer.end();++it){
std::cout<<*it<<std::endl;
}
return 0;
}


结果:

[b][color=red]
[System Process]
System
smss.exe
csrss.exe
winlogon.exe
services.exe
lsass.exe
ati2evxx.exe
svchost.exe
svchost.exe
svchost.exe
svchost.exe
svchost.exe
ZhuDongFangYu.exe
ati2evxx.exe
spoolsv.exe
ksdsvc.exe
sqlservr.exe
alg.exe
explorer.exe
RTHDCPL.EXE
360tray.exe
ctfmon.exe
360sd.exe
emule.exe
CBTray.exe
msnmsgr.exe
wlcomm.exe
TXPlatform.exe
QQ.exe
TXOPShow.exe
devenv.exe
XDict.exe
QQMusic.exe
360rp.exe
devenv.exe
conime.exe
QQ.exe
mspdbsrv.exe
devenv.exe
QQ.exe
devenv.exe
IEXPLORE.EXE
taskmgr.exe
cmd.exe
cmd.exe
Test.exe


[/color][/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值