How to get Process object of already running process?

ⅰ亾dé卋堺 提交于 2020-01-06 14:07:44

问题


I want a create a C++ program that can find an already running process and then redirect its Standard Output to my own stream for re-direction. I can find countless examples on how to start a new process but I want to try and do something like:

Process^ proc = new Process();
proc->Attach("notepad.exe");

And then have control over the already running notepad.exe process.. Is this possible? If not then I guess I can find a way to start the process from within my application, however then my question would be how can I start a process and send command-line arguments to the process as if I were starting it up in console.


回答1:


I believe you want GetProcessesByName. It will return an array of all the processes that match the name you give.

array<Process^>^ notepadProcesses = Process::GetProcessesByName("notepad");


来源:https://stackoverflow.com/questions/17115961/how-to-get-process-object-of-already-running-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!