I'm using some code to start the CLR Runtime inside a native process, then call my .NET DLL to load another .NET executable inside that process.
To load the other .NET executable I'm using reflection, like so:
Assembly.Load(file).EntryPoint.Invoke(null, null);
Now, I inject a C++ dll that starts the runtime, it then calls the .NET dll which uses Assembly.Load to load another .NET executable into memory and execute it.
Once the dll loads my .NET executable, calling:
System.Reflection.Assembly.GetExecutingAssembly().Location;
or even
Process.GetCurrentProcess().MainModule.FileName;
This, of course, returns the location of the executable itself, even though its running inside another host process. Is there any way I can grab the name of that host process? Process explorer shows it as running inside the host process so I know I have that part working correctly.
Of course if I were to run these commands inside the .NET DLL that was loaded first then it would show the proper process name.
Thanks.
EDIT:
I have tried GetEntryAssembly()
and GetCallingAssembly()
as well.
DON'T DO THAT.
You may not inject the .NET framework into any process that is not yours. It might have a different framework already loaded or desire to load a different framework version later.
You can get the name of the host process by calling GetModuleFileName(GetModuleHandle(NULL)); (Both API calls are P/Invoke. [1] and [2]).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With