Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change name of console app as displayed in task manager?

Tags:

c#

console

I am programmatically launching console applications. They all appear as conhost.exe in Task Manager.

How can I set a process name such that it appears as such in the task manager?

Example of how I'm setting up my process:

public static Process CreateMultiCoreExeProcess(int coreIndex, int coresToUse, string executableFilepath)
{
    //* Create your Process
    Process process = new Process
    {
        StartInfo =
        {
            FileName = executableFilepath,
            Arguments = coreIndex + " " + coresToUse,
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardOutput = true,
            RedirectStandardError = true
        },
        EnableRaisingEvents = true
    };

    return process;
}

...as you can see there isn't an attribute that sets the process name (that I know of). I would like to be able to set the name of the process at the time that I create it.

DUPLICATE QUESTION REMARK: this is not a duplicate as attempted. The solution presented as a duplicate is for a STATIC name for the process, being set within project properties. I am running my process DYNAMICALLY (at run time) and would like to set the process name at that time.

UPDATE: I am convinced that this isn't possible. At least not in a realistic (i.e. permanent) way. I'm fairly certain we are "stuck" with the name as provided in the assembly information and it can't be programmatically changed in the Task Manager. This is unfortunate for my application, which is to spawn 10+ identical process executables. Sometimes I want to kill just one of them, but I can't determine which-is-which in the task manager because they all have the same name.

like image 518
sapbucket Avatar asked Jan 07 '23 22:01

sapbucket


1 Answers

Use the line:

    Console.Title = "My Console Application";

to set the console name

And to set the name/description in task manager, it's been answered before quite a few times. Check this link How can I set the Task Manager description for my program?

like image 105
Ahmed Anwar Avatar answered Jan 29 '23 10:01

Ahmed Anwar