在任务管理器中更改程序进程名称? [英] Changing a programs process name in task manager?

查看:294
本文介绍了在任务管理器中更改程序进程名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我一直在环顾四周,但在任何地方都找不到答案.

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.

有一个叫做'Liberation'的程序,当你运行它时,它会将进程名称更改为一些随机字符,例如AeB4B3wf52.tmp 之类的.不过我不确定它是用什么编码的,所以这可能是问题所在.

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.

这在 C# 中可行吗?

Is this possible in C#?

我做了一个草率的工作,我创建了一个单独的程序来检查是否有一个名为pb.dat"的文件,它会将它复制到临时文件夹,将其重命名为randomchars.tmp"并运行它.

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.
}

推荐答案

我将实现一个主机应用程序来执行此操作,该应用程序仅运行和监视子进程(其他可执行文件).您可以将文件重命名为:

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.

这篇关于在任务管理器中更改程序进程名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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