The Compact Framework doesn’t support Assembly.GetEntryAssembly to determine the launching .exe. So is there another way to get the name of the executing .exe?
EDIT: I found the answer on Peter Foot’s blog: http://peterfoot.net/default.aspx Here is the code:
byte[] buffer = new byte[MAX_PATH * 2]; int chars = GetModuleFileName(IntPtr.Zero, buffer, MAX_PATH); if (chars > 0) { string assemblyPath = System.Text.Encoding.Unicode.GetString(buffer, 0, chars * 2); } [DllImport('coredll.dll', SetLastError = true)] private static extern int GetModuleFileName(IntPtr hModule, byte[] lpFilename, int nSize);
I am not sure whether it works from managed code (or even the compact framework), but in Win32 you can call GetModuleFileName to find the running exe file.
MSDN: GetModuleFileName