c++迭代进程并找出每个进程的命令行参数
C++ iterate processes and find out command line args of each process
我有以下问题要解决(VS2012, c++)我必须从我的exe中找出特定的HTA应用程序是否正在运行。为此,我必须找到进程mshta并检查它是否具有正确的参数(应该以"mshta someta .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 %sn"), szProcessName, processID );
// Release the handle to the process.
CloseHandle( hProcess );
}
我最终使用了这里提出的解决方案:http://www.codeproject.com/Articles/19685/Get-Process-Info-with-NtQueryInformationProcess
相关文章:
- 从命令行c++发送文本文件名
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 数组长度,为什么从命令行获取时不能使用它?
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- 从 C++ 中的二进制路径(命令行语句)获取进程 ID
- 创建进程命令行参数
- Windows 在创建进程时如何传递 ANSI 命令行
- C++ LPCTSTR 如何将命令行参数传递给子进程
- C++如何在进程之间传递命令行参数
- 任务管理器如何获取进程的命令行可执行路径
- 如何使用命令行参数创建一个新进程,并将PID提供给父进程
- 创建进程不会将命令行参数传递给新进程的主函数
- Visual Studio.如何构建DLL(在命令行中),通过附加到进程来调试工作
- 如何在Xcode的c++命令行应用程序中获取进程信息
- 运行进程命令行
- c++迭代进程并找出每个进程的命令行参数
- 正在Windows中获取另一个进程命令行
- 在多核 (Linux) 中运行进程的命令行参数是什么
- 运行命令行进程作为管理Qt