windows 下获取父进程pid
2017-08-31 11:15
1431 查看
DWORD GetParentProcessID(DWORD dwProcessId) { LONG status; DWORD dwParentPID = (DWORD)-1; HANDLE hProcess; PROCESS_BASIC_INFORMATION pbi; PROCNTQSIP NtQueryInformationProcess = (PROCNTQSIP)GetProcAddress( GetModuleHandle(L"ntdll"), "NtQueryInformationProcess"); if(NULL == NtQueryInformationProcess) { return (DWORD)-1; } // Get process handle hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE, dwProcessId); if (!hProcess) { return (DWORD)-1; } // Retrieve information status = NtQueryInformationProcess( hProcess, ProcessBasicInformation, (PVOID)&pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL ); // Copy parent Id on success if (!status) { dwParentPID = pbi.InheritedFromUniqueProcessId; } CloseHandle (hProcess); return dwParentPID; }
控制台中需要加入下面代码
#include <wtypes.h>: #define ProcessBasicInformation 0 typedef struct { DWORD ExitStatus; DWORD PebBaseAddress; DWORD AffinityMask; DWORD BasePriority; ULONG UniqueProcessId; ULONG InheritedFromUniqueProcessId; } PROCESS_BASIC_INFORMATION; // ntdll!NtQueryInformationProcess (NT specific!) // // The function copies the process information of the // specified type into a buffer // // NTSYSAPI // NTSTATUS // NTAPI // NtQueryInformationProcess( // IN HANDLE ProcessHandle, // handle to process // IN PROCESSINFOCLASS InformationClass, // information type // OUT PVOID ProcessInformation, // pointer to buffer // IN ULONG ProcessInformationLength, // buffer size in bytes // OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit // // variable that receives // // the number of bytes // // written to the buffer // ); typedef LONG (__stdcall *PROCNTQSIP)(HANDLE,UINT,PVOID,ULONG,PULONG);
相关文章推荐
- windows获取pid进程路径
- windows进程PID的获取以及杀死
- ndk获取Android进程PID和名称
- C#获取Windows进程监听的TCP/UDP端口实例
- Windows 下80端口被进程 System & PID=4 占用的解决方法
- Linux 父进程如何获取子进程返回值?parent get child process return value,fork,wait,wait_pid
- 使用Python在Windows下获取USB PID&VID
- Windows下80端口被pid为4的System进程占用解决方法
- Windows 2000命令行如何查看进程PID和杀进程
- Windows下用C语言获取进程cpu使用率,内存使用,IO情况
- windows获取进程流量
- 获取windows进程列表,并以字符串形式查询是否存在某一进程
- windows下有关端口和进程PID之间的关联
- Python获取pid和进程名字
- Atitit,通过pid获取进程文件路径 java php c#.net版本大总结
- 根据包名获取进程pid
- 使用Java获取windows进程的路径
- 已知进程pid获取其父进程pid
- JAVA实现获取Linux下进程PID并杀掉进程
- linux: 获取监听指定端口的进程PID