<p>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?</p>

<p>EDIT: I found the answer on Peter Foot's blog: <a href="http://peterfoot.net/default.aspx" rel="nofollow noreferrer">http://peterfoot.net/default.aspx</a>
Here is the code:</p>

<pre><code>byte[] buffer = new byte[MAX_PATH * 2];

int chars = GetModuleFileName(IntPtr.Zero, buffer, MAX_PATH);

if (chars &gt; 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);
</code></pre>

[{'answer_id': 25987, 'author': 'Timbo', 'author_id': 1810, 'author_profile': 'https://Stackoverflow.com/users/1810', 'pm_score': 3, 'selected': True, 'text': '<p>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.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms683197(VS.85).aspx" rel="nofollow noreferrer">MSDN: GetModuleFileName</a></p>\n'}, {'answer_id': 25990, 'author': 'Karim', 'author_id': 2494, 'author_profile': 'https://Stackoverflow.com/users/2494', 'pm_score': 0, 'selected': False, 'text': '<p>In managed code, i think you can use this:\n<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.executablepath.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.forms.application.executablepath.aspx</a></p>\n\n<p>Application.ExecutablePath</p>\n'}, {'answer_id': 117572, 'author': 'Martin Liesén', 'author_id': 20715, 'author_profile': 'https://Stackoverflow.com/users/20715', 'pm_score': 1, 'selected': False, 'text': '<pre><code>string exefile = Assembly.GetExecutingAssembly().GetName().CodeBase;\n</code></pre>\n\n<p>But if you put it in a DLL assembly, I believe it will give you the assembly file name.</p>\n\n<p>The same call on the "Full" framework would return the .exe file with a "file:\\" prefix.</p>\n'}]
['https://Stackoverflow.com/questions/25975', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1382/']