Question

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);
Was it helpful?

Solution

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

OTHER TIPS

string exefile = Assembly.GetExecutingAssembly().GetName().CodeBase;

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

The same call on the "Full" framework would return the .exe file with a "file:\" prefix.

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

Application.ExecutablePath

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top