How can I get the name of the executable .exe?

Compact Framework does not support Assembly.GetEntryAssembly for determining .exe startup. So, is there any other way to get the name of the executable .exe?

EDIT: I found the answer to the Peter Foot 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); 
+4
source share
3 answers

I'm not sure if this works with managed code (or even with a compact framework), but in Win32 you can call GetModuleFileName to find the exe executable.

MSDN: GetModuleFileName

+4
source
 string exefile = Assembly.GetExecutingAssembly().GetName().CodeBase; 

But if you put it in a DLL assembly, I believe that it will give you the name of the assembly file.

The same call in the "Full" structure will return the .exe file with the prefix "file: \".

+1
source

In managed code, I think you can use this: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.executablepath.aspx

Application.ExecutablePath

0
source

Source: https://habr.com/ru/post/1276427/


All Articles