How to get parent process in .NET in managed way

后端 未结 6 710
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 03:39

I was looking a lot for method to get parent process in .NET, but found only P/Invoke way.

6条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 04:18

    If accepting P/Invoke, there's a better way, which is more documented than NtQueryInformationProcess: namely PROCESSENTRY32 (CreateToolhelp32Snapshot, Process32First, Process32Next). It's shown in this post.

    Pay attention to the subtle details and note that parent PID is not necessarily the creator PID, in fact these may be completely unrelated, as pointed out by the community comments at PROCESSENTRY32.

提交回复
热议问题