如何获得真实的运行进程名称? [英] How to get real running process name?

查看:39
本文介绍了如何获得真实的运行进程名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .NET 核心控制台应用程序中,我想获取正在运行的进程名称,我使用了

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

打印This is my name,如下所示.

任务管理器显示

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

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

解决方案

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'

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

prints This is my name as shown below.

Task Manager displays

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

这篇关于如何获得真实的运行进程名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆