测试平台:win10 专业版 21H2 1904
编译平台:gcc version 12.2.0 (x86_64-posix-seh-rev2, Built by MinGW-W64 project)文章来源:https://www.toymoban.com/news/detail-516372.html
代码如下:文章来源地址https://www.toymoban.com/news/detail-516372.html
#include <stdio.h>
#include <winternl.h>
#include <Shlwapi.h>
#include<psapi.h>
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "shlwapi.lib")
unsigned long GetParentPID( unsigned long ProcessID);
void ShowProcName(unsigned long pid,char*);
int main(int argc, const char* argv[]) {
unsigned long ppid;
char pname[MAX_PATH] = {0};
ppid = GetParentPID(GetCurrentProcessId());
ShowProcName(ppid,pname);
printf("ParentProcessPID: %lu\n", ppid);
printf("ParentName: %s\n", pname);
system("pause");
return 0;
}
unsigned long GetParentPID(unsigned long ProcessID) {
/// 打开给定进程PID
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, ProcessID);
/// 下面是获取函数 NtQueryInformationProcess 的函数指
到了这里,关于Windows上获取父进程的一种简单方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!