Getting the running processes .exe name
How do you get the name of the running process (myapp.exe) from within a c# dll, which may be called from another dll within an exe.
I have tried
Assembly.GetExecutingAssembly which returns the dll name and Assembly.GetCallingAssembly which returns the name of the calling dll above.
What I think I should be calling is Assembly.GetEntryAssembly, however this is not supported by the compact framework.
Is there another way?
ok I found the answer for this myself using a native call, but i am sure others may want to know.
StringBuilder fileName =
new StringBuilder(255);
GetModuleFileName(IntPtr.Zero, fileName, fileName.Capacity);
[DllImport("coredll", SetLastError=true)]
[PreserveSig]
public static extern uint GetModuleFileName
(
[In]
IntPtr hModule,
[Out]
StringBuilder lpFilename,
[In]
[MarshalAs(UnmanagedType.U4)]
int nSize
);