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


当前回答

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

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

其他回答

试试这个:

System.Reflection.Assembly.GetExecutingAssembly()

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

更多选择:

System.Reflection.Assembly.GetExecutingAssembly () . getname () . name .CodeBase Path.GetFileName (System.Reflection.Assembly.GetExecutingAssembly () . getname ()

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

Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName);

这是对我有用的代码:

string fullName = Assembly.GetEntryAssembly().Location;
string myName = Path.GetFileNameWithoutExtension(fullName);

上面所有的例子都给了我带有vshost或运行dll名称的processName。

这就足够了:

Environment.GetCommandLineArgs()[0];