我想要获得当前运行程序的名称,即程序的可执行名称。在C/ c++中,你从args[0]中得到它。


当前回答

System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name;

会给你应用的文件名,比如;“MyApplication.exe”

其他回答

来获取路径和名称

.MainModule.FileName System.Diagnostics.Process.GetCurrentProcess ()

这是你想要的吗?

Assembly.GetExecutingAssembly ().Location

如果您要在。net 6.0或更高版本中发布单文件应用程序,则可以使用Environment。ProcessPath

试试这个:

System.Reflection.Assembly.GetExecutingAssembly()

这将返回一个System.Reflection.Assembly实例,其中包含您希望了解的有关当前应用程序的所有数据。我认为Location属性可能会得到你想要的。

如果你只需要应用程序名而不需要扩展名,这是有效的:

Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName);