Tim
Tim

Reputation: 105

Changing a programs process name in task manager?

Okay so I've been looking around and I can't find an answer anywhere.

What I want my program to do is every time I run it, the name that shows up in the task manager is randomized.

There is a program called 'Liberation' that when you run it, it will change the process name to some random characters like AeB4B3wf52.tmp or something. I'm not sure what it is coded in though, so that might be the issue.

Is this possible in C#?

Edit: I made a sloppy work around, I created a separate program that will check if there is a file named 'pb.dat', it will copy it to the temp folder, rename it to a 'randomchars.tmp' and run it.

Code if anyone was interested:

private void Form1_Load(object sender, EventArgs e)
{
    try
    {
        if (!Directory.Exists(Environment.CurrentDirectory + @"\temp")) // Create a temp directory.
            Directory.CreateDirectory(Environment.CurrentDirectory + @"\temp");

        DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory + @"\temp");

        foreach (FileInfo f in di.GetFiles()) // Cleaning old .tmp files
        {
            if (f.Name.EndsWith(".tmp"))
                        f.Delete();
        }

        string charList = "abcdefghijklmnopqrstuvwxyz1234567890";
        char[] trueList = charList.ToCharArray();
        string newProcName = "";

        for (int i = 0; i < 8; i++) // Build the random name
            newProcName += trueList[r.Next(0, charList.Length)];

        newProcName += ".tmp";

        if (File.Exists(Environment.CurrentDirectory + @"\pb.dat")) // Just renaming and running.
        {
            File.Copy(Environment.CurrentDirectory + @"\pb.dat", Environment.CurrentDirectory + @"\temp\" + newProcName);
            ProcessStartInfo p = new ProcessStartInfo();
            p.FileName = Environment.CurrentDirectory + @"\temp\" + newProcName;
            p.UseShellExecute = false;
            Process.Start(p);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("I caught an exception! This is a bad thing...\n\n" + ex.ToString(), "Exception caught!");
    }

    Environment.Exit(-1); // Close this program anyway.
}

Upvotes: 1

Views: 16262

Answers (3)

bmo
bmo

Reputation: 121

in visual studio go to Project - Properties - Application - Assembly information and change Title

Upvotes: 2

Marcus
Marcus

Reputation: 8659

I would implement a host application to do this that simply runs and monitors a sub process (other executable). You may rename a file as such:

System.IO.File.Move("oldfilename", "newfilename");

and start the process like this:

Process.Start("newfilename");

This would mean that instead of one process you would have two, but the owner process only needs to be alive under startup - in order to change the name.

Upvotes: 0

CloudyMarble
CloudyMarble

Reputation: 37566

The process name in the task manager bases on the executable name without the extension, which you can not change while it is running.

Read the documentation:

The ProcessName property holds an executable file name, such as Outlook, that does not include the .exe extension or the path. It is helpful for getting and manipulating all the processes that are associated with the same executable file.

Upvotes: 1

Related Questions