zoukankan      html  css  js  c++  java
  • [Win32]获取指定进程的父进程PID

     1 //
     2 //
     3 
     4 #include <Windows.h>
     5 #include <winnt.h>
     6 #include <winternl.h>
     7 
     8 typedef NTSTATUS (__stdcall * NTQUERYINFORMATIONPROCESS)
     9 (
    10     HANDLE ProcessHandle,
    11     PROCESSINFOCLASS ProcessInformationClass,
    12     PVOID ProcessInformation,
    13     ULONG ProcessInformationLength,
    14     PULONG ReturnLength
    15 );
    16 
    17 int _tmain(int argc, _TCHAR* argv[])
    18 {
    19     int errCode = 0;
    20 
    21     HMODULE hMod = GetModuleHandle(L"NTDLL.DLL");
    22     if (hMod == NULL)
    23     {
    24         return 0;
    25     }
    26 
    27     NTQUERYINFORMATIONPROCESS ptrNtQueryInformationProcess = (NTQUERYINFORMATIONPROCESS)GetProcAddress(hMod, NtQueryInformationProcess");
    28     if (ptrNtQueryInformationProcess == NULL)
    29     {
    30         return 0;
    31     }
    32 
    33     PROCESS_BASIC_INFORMATION processBasicInformation;
    34     ULONG retLength = 0;
    35     NTSTATUS status = ptrNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, processBasicInformation, sizeof(processBasicInformation), retLength);
    36 
    37     return errCode;
    38 }
    39 
    40 //

    在 PROCESS_BASIC_INFORMATION 结构体中,Reserved3字段保存的是父进程ID,强制转换成DWORD即可。

  • 相关阅读:
    超媒体
    超文本
    视频文件格式
    web.py 模板错误记录
    pip常用记录
    微信公众号绑定服务器 Flask版
    scrapy 简单防封
    python 手写队列
    jQuery个人总结
    PHP用url传递数组
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/3391222.html
Copyright © 2011-2022 走看看