0

My C# application is going to be executed by another exe file. When my application is loaded, I need to get the calling exe file path.

I can get my own application path by following code;

  Application.ExecutablePath;

But how to get the caller exe path? Any help would be highly appreciated.

nawala
  • 115
  • 10
  • 1
    The executable path of the process who called `CreateProcess` that started your application ? – TheGeneral Aug 27 '20 at 07:35
  • 1
    How is it "called"? Is it used like a lib or via `Process.Start()` ? – Fildor Aug 27 '20 at 07:36
  • Michael Randall The caller application is not owned by me. So I'am not able to pass it's path to my application. Any idea? – nawala Aug 27 '20 at 07:37
  • 1
    Fildor, I think it is called using Process.Start() – nawala Aug 27 '20 at 07:38
  • 1
    Get the `parent process` as shown [here](https://stackoverflow.com/questions/394816/how-to-get-parent-process-in-net-in-managed-way) and retrieve its path. – Axel Kemper Aug 27 '20 at 07:40
  • 1
    ^^ Mind to look into [Simon's answer](https://stackoverflow.com/a/3346055/982149) over the accepted one. – Fildor Aug 27 '20 at 07:43
  • The code by Simon Mourier given me the IDE path on debugging, but compiled code returns null value when called by other exe. what may be the cause? – nawala Aug 27 '20 at 08:23
  • Fildor, Axel Kemper I think the caller exe is exiting before the code executes. What may be the alternative methods? – nawala Aug 27 '20 at 08:44

0 Answers0