首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我只想要一个可执行文件来枚举进程和枚举加载的.dlls

我只想要一个可执行文件来枚举进程和枚举加载的.dlls
EN

Stack Overflow用户
提问于 2013-05-27 15:29:33
回答 1查看 92关注 0票数 1

我想做一个like函数,它的参数是进程名的stdvector::<std::string>和.dll的std::vector<std::string>,以便在它们中找到并将其提供给一个函数,并获得匹配名称的任何内容的PROCESSENTRY32信息std::vector<PROCESSENTRY32>返回。

你可以在谷歌上搜索,但不会找到太多,因为我感谢你帮助winapi新手,但不是为了弄清楚事情

EN

回答 1

Stack Overflow用户

发布于 2013-05-27 16:31:56

有一个完美的例子可以完全按照你想要的on MSDN here来做。下面复制了相关代码。正如示例的介绍所说的那样

若要确定哪些进程加载了特定的DLL,必须枚举每个进程的模块。下面的示例代码使用EnumProcessModules函数枚举系统中当前进程的模块。

下面是示例代码

代码语言:javascript
复制
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <psapi.h>

// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
// and compile with -DPSAPI_VERSION=1

int PrintModules( DWORD processID )
{
    HMODULE hMods[1024];
    HANDLE hProcess;
    DWORD cbNeeded;
    unsigned int i;

    // Print the process identifier.
    printf( "\nProcess ID: %u\n", 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))
    {
        for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
        {
            TCHAR szModName[MAX_PATH];

            // Get the full path to the module's file.
            if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
                sizeof(szModName) / sizeof(TCHAR)))
            {
                // Print the module name and handle value.
                _tprintf( TEXT("\t%s (0x%08X)\n"), szModName, hMods[i] );
            }
        }
    }

    // Release the handle to the process.
    CloseHandle( hProcess );

    return 0;
}

int main( void )
{

    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 ( i = 0; i < cProcesses; i++ )
    {
        PrintModules( aProcesses[i] );
    }

    return 0;
}

您需要做的惟一更改是预先将感兴趣的模块名称push-back到您的std::vector<std::string>中,然后使用枚举的模块名称搜索该向量,而不是打印它们。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16768329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档