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
IF you are looking for the full path information of your executable, the reliable way to do it is to use the following:
This eliminates any issues with intermediary dlls, vshost, etc.
Super easy, here:
Try Application.ExecutablePath
You can use
Environment.GetCommandLineArgs()
to obtain the arguments andEnvironment.CommandLine
to obtain the actual command line as entered.Also, you can use
Assembly.GetEntryAssembly()
orProcess.GetCurrentProcess()
.However, when debugging, you should be careful as this final example may give your debugger's executable name (depending on how you attach the debugger) rather than your executable, as may the other examples.
System.Diagnostics.Process.GetCurrentProcess()
gets the currently running process. You can use theProcessName
property to figure out the name. Below is a sample console app.When uncertain or in doubt, run in circles, scream and shout.
I can't claim to have tested each option, but it doesn't do anything stupid like returning the vhost during debugging sessions.