在Windows中设置子进程名称? [英] Set child process name in Windows?

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

问题描述

我有进程,运行多次子进程(每个没有GUI),它需要设置为所有子进程不同的名称和描述任务管理器。是否可以使用Win API?我找不到Windows系列的解决方案。

I have process, that run multiple times child processes (each without GUI), and it needs to set to all child processes different "names" and "description" for Task Manager. Is it possible using Win API? I can't find solution for Windows family.

我看看WriteProcessMemory,但它看起来像作弊的形式,即使有可能更改名称。
解决方案与复制.exe文件,运行它,过程完成后 - 删除它 - 甚至更多的欺骗。
可能存在解决方案使用启动过程从内存(所以,我加载EXE文件到内存,然后从那里启动它),但它也看起来不好,我不知道我将能够更改名称。

I look to WriteProcessMemory, but it looks like form of cheating, even if there is possible to change name. Solution with copying .exe file, run it, and after process finished - deleting it - is even more cheating. There may be exist solution using start process from memory (so, I load exe file to memory, then start it from there), but it also looks bad and I'm not sure I will be able to change name.

我希望有一个解决方案来设置进程名为我自己的子进程,不是吗?

I hope there have to be solution to set process name to my own child process, isn't it?

推荐答案

您不能更改任务管理器中显示的映像名称。正如你所发现的,Windows从实际执行的文件的名称获得,并且唯一的方法有不同的出现是实际运行一个不同的名称的文件(例如通过复制可执行文件)。

You can't change the "Image Name" that appears in Task Manager. As you found, Windows obtains that from the name of the file that is actually executing and the only way to have something different appear is to actually run a file with a different name (such as by copying your executable).

如果您的目标是较新版本的Windows,任务管理器可以显示一个命令行列(视图 - >选择列)。你可以通过在命令行中包含一个特定的标志,或者通过将 lpCommandLine 参数的第一个标志设置为唯一的来使你的进程可以区分 - 你只需要设置 lpApplicationName 参数为您要运行的实际可执行文件,以便加载器可以找到它。

If you are targeting newer versions of Windows, Task Manager can display a "Command Line" column (View -> Select Columns). You can make your processes distinguishable by including a particular flag in the command line, or by setting the first token of the lpCommandLine argument to something unique - you just have to also set the lpApplicationName argument to the actual executable you want to run so the loader can find it.

p>

For example:

BOOL ret1 = CreateProcess(
               "c:\\program\\worker.exe",
               "worker1.exe infile outfile",
               ...);

BOOL ret2 = CreateProcess(
               "c:\\program\\worker.exe",
               "worker2.exe infile outfile",
               ...);

这些将在任务管理器中具有相同的图像名称值,但它们可以通过命令行值。

These will have identical Image Name values in Task Manager, but they will be distinguishable by the Command Line values.

这篇关于在Windows中设置子进程名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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