好了,所以我一直在寻找周围,我不能在任何地方找到答案。在任务管理器中更改程序进程名称?
我想要什么我的程序做的是我每次运行时,在任务管理器中显示的名称是随机的。
有一个名为“解放”,当你运行它,它会进程名称更改为一些随机字符,如AeB4B3wf52.tmp什么程序。我不确定它是在什么编码,所以这可能是问题。
这是可能的C#?
编辑︰ 我做了一个马虎的工作,我创建了一个单独的程序,将检查是否有一个名为'pb.dat'的文件,它会将其复制到临时文件夹,将其重命名为'randomchars。 tmp“并运行它。
代码,如果有人有兴趣:
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.
}
听起来像是你正在编写一个病毒:) – Andrew
@Andrew:哈哈,+1!无论如何,这是在互联网上找到的! http://stackoverflow.com/questions/1055987/c-how-to-set-an-projects-executable-processname – dqm
这有点一所学校的项目,我正在写一个程序阻止程序关闭特定的进程,以及老师建议让名字随机化哈哈。 – Tim