如何得到C#中當前可執行文件的名稱?

我想獲取當前正在運行的程序的名稱,即該程序的可執行名稱。 在C / C ++中,您能夠從args[0]得到它。 spa


#1樓

這是爲我工做的代碼: code

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

上面全部示例爲我提供了帶有vshost或正在運行的dll名稱的processName。 內存


#2樓

若是您正在尋找可執行文件的完整路徑信息,那麼執行此操做的可靠方法是使用如下命令: string

var executable = System.Diagnostics.Process.GetCurrentProcess().MainModule
                       .FileName.Replace(".vshost", "");

這消除了中間dll,vshost等的任何問題。 it


#3樓

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

將爲您提供應用程序的文件名,例如: 「 MyApplication.exe」 io


#4樓

  • 若是未從內存中加載程序集,則System.Reflection.Assembly.GetEntryAssembly().Location返回exe名稱的位置。
  • System.Reflection.Assembly.GetEntryAssembly().CodeBase返回位置做爲URL。

#5樓

爲何沒人建議這個,很簡單。 table

Path.GetFileName(Application.ExecutablePath)
相關文章
相關標籤/搜索