如何获取已经运行的进程的Process对象? [英] How to get Process object of already running process?

查看:559
本文介绍了如何获取已经运行的进程的Process对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个C ++程序,可以找到一个已经运行的进程,然后将其标准输出重定向到我自己的流重定向。我可以找到无数的例子,如何开始一个新的过程,但我想尝试做一些像:

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");

然后可以控制已经运行的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.

推荐答案

我相信你想要 GetProcessesByName 。它将返回与您给出的名称匹配的所有进程的数组。

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");

这篇关于如何获取已经运行的进程的Process对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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