How to get real running process name?

2019-07-26 08:46发布

In a .NET core console app, I'd like to get the running process name, I used ProcessName as the docs say, but it always returns dotnet as the process name, not the actual underline dll that is running. Although it is a dll, this is a console app, not a library.

Console.WriteLine(Process.GetCurrentProcess().ProcessName);

output

dotnet

1条回答
我只想做你的唯一
2楼-- · 2019-07-26 09:33

EDIT:

For .net core you could use:

 System.Reflection.Assembly.GetEntryAssembly().FullName

or

 System.Reflection.Assembly.GetEntryAssembly().GetName().Name

For .NET

For a project with Assmebly Name 'This is my name'

enter image description here

Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().ProcessName);

prints This is my name as shown below.

enter image description here

Task Manager displays

 [assembly: AssemblyTitle("This is my name Title")]

enter image description here

查看更多
登录 后发表回答