How do I get the name of the current executable in C#?


Question

I want to get the name of the currently running program, that is the executable name of the program. In C/C++ you get it from args[0].

1
333
4/3/2017 7:04:14 PM

Accepted Answer

System.AppDomain.CurrentDomain.FriendlyName
389
3/5/2009 9:33:15 PM

System.AppDomain.CurrentDomain.FriendlyName - Returns the filename with extension (e.g. MyApp.exe).

System.Diagnostics.Process.GetCurrentProcess().ProcessName - Returns the filename without extension (e.g. MyApp).

System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName - Returns the full path and filename (e.g. C:\Examples\Processes\MyApp.exe). You could then pass this into System.IO.Path.GetFileName() or System.IO.Path.GetFileNameWithoutExtension() to achieve the same results as the above.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon