获取正在运行的进程的模块数
Get number of modules of a running process
我试图通过传递进程ID
来获取正在运行的进程的模块总数 这是返回进程中模块总数的函数
int size(DWORD processID)
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
// Print the process identifier.
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID);
// Get a list of all the modules in this process.
EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded);
int j = (cbNeeded / sizeof(HMODULE));
return j;
// Release the handle to the process.
}
这是主要的
int main()
{
DWORD aProcesses[1024];
DWORD cbNeeded;
DWORD cProcesses;
unsigned int i;
// Get the list of process identifiers.
if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
return 1;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the names of the modules for each process.
for (int i = 0; i <= cProcesses; i++) {
int a = size(aProcesses[1]);
//std::string* g = PrintModules(aProcesses[1], a);
cout << a << endl;
}
system("pause");
return 0;
}
当我编译和运行时,此代码输出855987977等 我尝试了多种方法,但都是徒劳的...
使用 EnumprocessModule 的标准方法,输出参数是数组的大小(以字节为单位(:
lpcbNeeded = The number of bytes required to store all module handles in the lphModule array.
将其除以元素类型(HMODULE(的大小,这将得到模块的数量。
int GetNumberOfModules(DWORD processID)
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
// Print the process identifier.
printf("nProcess ID: %un", processID);
// Get a handle to the process.
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID);
if (NULL == hProcess)
return 1;
// Get a list of all the modules in this process.
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
{
//return number of modules by dividing size of array by element size
return cbNeeded / sizeof(HMODULE);
}
// Release the handle to the process.
CloseHandle(hProcess);
return 0;
}
相关文章:
- boost::进程间消息队列引发错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 是否可以通过C++扩展强制多个python进程共享同一内存
- IPC使用多个管道和分支进程来运行Python程序
- 异常属于C++中的线程还是进程
- WMI检测进程创建事件-c++
- c++多进程编写一个唯一的文件
- 如何在C++中将函数发送到另一个进程
- 枚举进程模块在有效句柄上返回无效句柄
- 通过进程模块C 枚举时,访问被拒绝
- Visual Studio 在附加到进程时不会加载模块
- 强制卸载进程的模块
- 在同一进程中使用的两个模块中具有同步对象的通用名称是否安全
- 从其他进程获取模块句柄
- 使用Module32First/Next从64位进程中枚举32位进程模块
- 如何将事件处理程序附加到本机 Node.js 模块中的进程出口?
- 内存模块是否映射到进程的虚拟空间?
- 无法在具有无限循环的 boost.python 模块中通过 Ctrl-c 杀死进程
- 列出Windows进程和模块