问题
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