Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 获取每个流程的流程信息_Windows_Winapi_Process_Wc - Fatal编程技术网

Windows 获取每个流程的流程信息

Windows 获取每个流程的流程信息,windows,winapi,process,wc,Windows,Winapi,Process,Wc,我试图创建一个程序,任何普通用户都可以在windows上运行,并生成所有进程的进程列表,包括可执行文件的位置。我使用CreateToolhelp32Snapshot()获取所有进程名、pid、ppid。但是在获取图像路径时遇到问题。我所做的一切都会导致访问被拒绝 我尝试过ZwQueryInformationProcess、GetProcessImageFileName等,还使用OpenProcess获得每个进程的句柄。我可以通过使用PROCESS\u QUERY\u LIMITED\u信息获得句

我试图创建一个程序,任何普通用户都可以在windows上运行,并生成所有进程的进程列表,包括可执行文件的位置。我使用CreateToolhelp32Snapshot()获取所有进程名、pid、ppid。但是在获取图像路径时遇到问题。我所做的一切都会导致访问被拒绝


我尝试过ZwQueryInformationProcess、GetProcessImageFileName等,还使用OpenProcess获得每个进程的句柄。我可以通过使用PROCESS\u QUERY\u LIMITED\u信息获得句柄,但任何其他选项都不起作用。我迷路了,已经在这里呆了几天了。有人能给我指出正确的方向吗?

这是适用于Windows上非管理员用户的代码。使用PROCESSENTRY32的szexFile成员获取路径:

HANDLE hProcessSnap = NULL;
HANDLE hProcess = NULL;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass = 0;

// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
    return;
}

// Set the size of the structure before using it.
pe32.dwSize = sizeof(PROCESSENTRY32);

// Retrieve information about the first process,
// and exit if unsuccessful
if (!Process32First(hProcessSnap, &pe32))
{
    CloseHandle(hProcessSnap);          // clean the snapshot object
    return;
}

// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
    // do something with the pe32 struct.
    // pe32.szExeFile -> path of the file

} while (Process32Next(hProcessSnap, &pe32));

CloseHandle(hProcessSnap);

调用
OpenProcess()
时,不应使用
PROCESS\u ALL\u ACCESS
。只要求你实际需要的权利。例如,
GetPriorityClass()
只需要
处理查询信息
处理查询有限信息
。但是,本例没有对任何内容使用
hProcess
,因此您甚至不需要调用
OpenProcess()