简体   繁体   English

如何在C / C ++中创建新进程并在WinXp中获得此新进程句柄?

[英]How to create a new process in C/C++ and get this new process handle in WinXp?

I need to know how to get a handle of a newly created process in C/C++ code. 我需要知道如何用C / C ++代码处理新创建的进程。 I don't know much about all those Microsoft libraries and I've just read about 2 ways to create a process. 我对所有这些Microsoft库都不是很了解,我只读了两种创建过程的方法。 First is via ShellExcecute call and the second via CreateProcess but none of these retern a HANDLE. 第一个是通过ShellExcecute调用,第二个是通过CreateProcess,但是这些都不是HANDLE。 I need to know a handle of the process because I want the main thread to wait for process to finish before it continues. 我需要知道进程的句柄,因为我希望主线程在进程继续之前先等待进程完成。 Best of all I'd like if someone help me write a function which looks like this: 最重要的是,如果有人帮助我编写如下所示的函数:

HANDLE create_process(/*parameters same as for ShellExecute*/)
{
    ...
}

Please help. 请帮忙。

CreateProcess() returns a PROCESS_INFORMATION structure which contains the process handle. CreateProcess()返回包含过程句柄的PROCESS_INFORMATION结构。 See here and here . 看到这里这里

Whilst ShellExecute() does not give you the information that you need, ShellExecuteEx() returns the process handle in the SHELLEXECUTEINFO structure. 尽管ShellExecute()没有提供所需的信息,但ShellExecuteEx()SHELLEXECUTEINFO结构中返回进程句柄。 See here and here . 看到这里这里

I would suggest that you look at the MSDN documentation for the API functions that you're using as it's very useful. 我建议您查看正在使用的API函数的MSDN文档,因为它非常有用。

CreateProcessPROCESS_INFORMATION返回处理的句柄。

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

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