我想獲取當前正在運行的程序的名稱,即該程序的可執行名稱。 在C / C ++中,您能夠從args[0]
得到它。 spa
這是爲我工做的代碼: code
string fullName = Assembly.GetEntryAssembly().Location; string myName = Path.GetFileNameWithoutExtension(fullName);
上面全部示例爲我提供了帶有vshost或正在運行的dll名稱的processName。 內存
若是您正在尋找可執行文件的完整路徑信息,那麼執行此操做的可靠方法是使用如下命令: string
var executable = System.Diagnostics.Process.GetCurrentProcess().MainModule .FileName.Replace(".vshost", "");
這消除了中間dll,vshost等的任何問題。 it
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name;
將爲您提供應用程序的文件名,例如: 「 MyApplication.exe」 io
System.Reflection.Assembly.GetEntryAssembly().Location
返回exe名稱的位置。 System.Reflection.Assembly.GetEntryAssembly().CodeBase
返回位置做爲URL。 爲何沒人建議這個,很簡單。 table
Path.GetFileName(Application.ExecutablePath)