简体   繁体   English

在Windows中设置子进程名称?

[英]Set child process name in 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. 我有一个进程,该进程运行多次子进程(每个进程都没有GUI),并且它需要为所有子进程设置任务管理器的不同“名称”和“描述”。 Is it possible using Win API? 是否可以使用Win API? I can't find solution for Windows family. 我找不到Windows系列的解决方案。

I look to WriteProcessMemory, but it looks like form of cheating, even if there is possible to change name. 我看了看WriteProcessMemory,但它看起来像作弊形式,即使可以更改名称也是如此。 Solution with copying .exe file, run it, and after process finished - deleting it - is even more cheating. 复制.exe文件,运行它以及在过程完成后删除它的解决方案-删除它-甚至更有弊。 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. 可能存在使用内存中的启动过程的解决方案(因此,我将exe文件加载到内存中,然后从那里启动它),但它看起来也很糟糕,我不确定是否可以更改名称。

I hope there have to be solution to set process name to my own child process, isn't it? 我希望必须有解决方案才能将进程名称设置为我自己的子进程,不是吗?

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从实际正在执行的文件的名称中获取该信息,并且使外观有所不同的唯一方法是实际运行具有不同名称的文件(例如,通过复制可执行文件)。

If you are targeting newer versions of Windows, Task Manager can display a "Command Line" column (View -> Select Columns). 如果您以Windows的较新版本为目标,则任务管理器可以显示“命令行”列(“视图”->“选择列”)。 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. 您可以通过在命令行中包含特定标志,或将lpCommandLine参数的第一个标记设置为唯一的东西来使您的进程与众不同-您只需将lpApplicationName参数设置为要运行的实际可执行文件,即可使加载程序可以找到它。

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. 这些在“任务管理器”中将具有相同的“映像名称”值,但可以通过命令行值加以区分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM