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


当前回答

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

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

其他回答

如果您需要程序名称来设置防火墙规则,请使用:

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

这将确保在VisualStudio中调试和在windows中直接运行应用程序时名称是正确的。

试试这个:

System.Reflection.Assembly.GetExecutingAssembly()

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

这就足够了:

Environment.GetCommandLineArgs()[0];

来获取路径和名称

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

System.AppDomain.CurrentDomain.FriendlyName