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


当前回答

这是你想要的吗?

Assembly.GetExecutingAssembly ().Location

其他回答

System.Diagnostics.Process.GetCurrentProcess()获取当前正在运行的进程。您可以使用ProcessName属性来确定名称。下面是一个示例控制台应用程序。

using System;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(Process.GetCurrentProcess().ProcessName);
        Console.ReadLine();
    }
}
System.AppDomain.CurrentDomain.FriendlyName

这是对我有用的代码:

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

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

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

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

这是你想要的吗?

Assembly.GetExecutingAssembly ().Location