Is there a reliable way to know what executable has called my executable?
I have a .NET executable but I would like to know who has started my application.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s an answer to your question http://www.codeproject.com/KB/threads/ParentPID.aspx
In short, you create a snapshot of all processes running with
lpfCreateToolhelp32Snapshot(), then iterate through it to find your process (identified byGetCurrentProcessId()) withlpfProcess32First()/lpfProcess32Next(). Once you found your own process, the structure you get gives you process id of the parent process, the one that has run your app.Once you get parent PID, it is easy to get filename of exe file and other attributes with
EnumProcessModules()andGetModuleFileNameEx().But you can probably just use the code from the link.