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]
.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
will give you FileName of your app like; "MyApplication.exe"
If you need the Program name to set up a firewall rule, use:
This will ensure that the name is correct both when debugging in VisualStudio and when running the app directly in windows.
For windows apps (forms and console) I use this:
Add a reference to System.Windows.Forms in VS then:
This works correctly for me whether I am running the actual executable or debugging within VS.
Note that it returns the application name without the extension.
John
On .Net Core (or Mono), most of the answers won't apply when the binary defining the process is the runtime binary of Mono or .Net Core (dotnet) and not your actual application you're interested in. In that case, use this:
Is this what you want: