博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
遍历Windows系统中所有进程的名字(*.exe)
阅读量:4044 次
发布时间:2019-05-24

本文共 1512 字,大约阅读时间需要 5 分钟。

2014年3月21日11:32:21

1、使用VS2008创建一个预编译头的控制台项目。

2、源文件内容:

#include "stdafx.h"#include 
#include
#include
using namespace std;#pragma once#pragma message("Psapi.h --> Linking with Psapi.lib")#pragma comment(lib,"Psapi.lib")// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS// and compile with -DPSAPI_VERSION=1void PrintProcessNameAndID( DWORD processID ){ TCHAR szProcessName[MAX_PATH] = TEXT("
"); // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) ); } } // Print the process name and identifier. _tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID ); // Release the handle to the process. CloseHandle( hProcess );}int main( void ){ // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) { return 1; } // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) { if( aProcesses[i] != 0 ) { PrintProcessNameAndID( aProcesses[i] ); } } char ch; cin>>ch; return 0;}

转载地址:http://tcwci.baihongyu.com/

你可能感兴趣的文章
慢慢欣赏linux make uImage流程
查看>>
linux内核学习(7)脱胎换骨解压缩的内核
查看>>
以太网基础知识
查看>>
慢慢欣赏linux 内核模块引用
查看>>
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
Homebrew指令集
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>
React Native(二):属性、状态
查看>>
JSX使用总结
查看>>
React Native(四):布局(使用Flexbox)
查看>>
React Native(七):Android双击Back键退出应用
查看>>
Android自定义apk名称、版本号自增
查看>>
adb command not found
查看>>
Xcode 启动页面禁用和显示
查看>>
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Reorder List (python)
查看>>