为什么 GetProcessImageFileName 返回 null 而不是进程的地址
Why does GetProcessImageFileName return null instead of the address of the process?
我正在尝试汇集Qt中所有进程的列表。以下代码演示了我到目前为止的努力:
QList<QString> frmProcess::GetAllRunningProcesses()
{
HANDLE hSysSnapshot = NULL;
HANDLE processHandle;
PROCESSENTRY32 proc;
proc.dwSize = sizeof(proc);
hSysSnapshot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 );
Process32First(hSysSnapshot,&proc);
proc.dwSize = sizeof(proc);
ui->listWidget->clear();
LPWSTR processPath;
list.clear();
do
{
//This block of code is to get each process's path and store it in a list
//PROCESS_ALL_ACCESS is commented out since it fails the program on start-up
processHandle = OpenProcess( /*PROCESS_ALL_ACCESS*/PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, proc.th32ProcessID );
GetProcessImageFileName(processHandle,processPath,MAX_PATH);
procpaths.append(QString::fromWCharArray(processPath));
list.append(QString::fromWCharArray(proc.szExeFile));
} while(Process32Next(hSysSnapshot,&proc));
CloseHandle( hSysSnapshot );
return list;
}
在上面发布的代码中,我正在尝试获取尽可能多的有关进程的信息,为此,我在CreateToolhelp32Snapshot
的帮助下汇集进程名称,然后通过GetProcessImageFileName
获取它们的路径。所有这些都发生在每毫秒的计时器时钟周期事件中。
如果我运行该程序,几秒钟后它崩溃了,我得到分段错误。
我也尝试了调试,因为我无法获得与任何进程相关的任何路径!
令我惊讶的是,我只得到每个进程路径的空字符串!我做错了什么?
您的GetProcessImageFileName
没有收到正确的参数。 processPath
必须指向有效的缓冲区。
TCHAR processPath[MAX_PATH] = { 0 };
GetProcessImageFileName(processHandle, processPath, _countof(processPath));
此外,您要检查返回的值以查看是否成功。
相关文章:
- 如何读取特定地址的进程内存?
- 两个不同的进程,在同一地址上有 2 个 std::atomic 变量?
- C++如何使用读取进程内存查找进程内存中使用的最后一个(偏移量 - 地址)
- 使用 ReadProcessMemory 从进程读取相对于基址的地址
- 如何使用 C# 在 Windows 中获取另一个进程库地址
- 写入进程内存没有错误,它不会写入正确的地址
- 内存中进程的实际起始地址/W32调试API
- 为什么 GetProcessImageFileName 返回 null 而不是进程的地址
- 从注入进程的 DLL 调用函数并更改指针函数的地址
- 如何从wow64进程中检索特定内核对象的64位地址
- 从进程读取地址
- 如何在C++中获取进程的起始地址/基地址
- 进程如何访问不属于其虚拟地址空间的内存映射 IO 地址?
- 从另一个进程中查找变量的地址
- 获取C++中的另一个进程变量值(或内存地址)
- 以何种形式,可以通过管道将空指针发送到不同进程地址空间中的另一个进程
- 更新进程地址空间中的HTML内容
- 如何判断共享库在进程地址空间中的加载位置
- 一个IP地址和一个端口号可以一起唯一地标识一个进程ID吗
- 如何查找进程地址空间的地址?