【问题标题】:C++ iterate processes and find out command line args of each processC++ 迭代进程并找出每个进程的命令行参数
【发布时间】:2016-08-31 13:06:52
【问题描述】:

我有以下问题要解决(VS2012,C++) 我必须确定某个特定的 HTA 应用程序是否正在从我的 exe 运行。为此,我必须找到进程 mshta 并检查它是否有正确的参数(应该以“mshta somehta.hta”开始)。我的第一次尝试是迭代进程/模块,我现在可以这样做。我看到列出的 mshta 及其 PID。但是,我没有找到获取信息的方法,它是如何开始的。有办法吗?

ProcessExists(wchar_t* processName)
{
    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
    {
        return false;
    }


    // 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] );
        }
    }

    return false;

 }
 void PrintProcessNameAndID( DWORD processID )
{
    TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");

    // 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.

    dprintf( TEXT("%s  (PID: %u) %s %s\n"), szProcessName, processID );

   // Release the handle to the process.

   CloseHandle( hProcess );
}

【问题讨论】:

标签: c++ process module arguments psapi


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    相关资源
    最近更新 更多