如何调用:: CreateProcess在c ++中以启动Windows可执行文件? [英] How do I call ::CreateProcess in c++ to launch a Windows executable?

查看:100
本文介绍了如何调用:: CreateProcess在c ++中以启动Windows可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一个例子:


  1. 启动EXE

  2. 等待EXE


解决方案正确地关闭所有句柄。 / div>

这样的东西:

  STARTUPINFO info = {sizeof(info)}; 
PROCESS_INFORMATION processInfo;
if(CreateProcess(path,cmd,NULL,NULL,TRUE,0,NULL,NULL,& info,& processInfo))
{
WaitForSingleObject(processInfo.hProcess,INFINITE) ;
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}


Looking for an example that:

  1. Launches an EXE
  2. Waits for the EXE to finish.
  3. Properly closes all the handles when the executable finishes.

解决方案

Something like this:

STARTUPINFO info={sizeof(info)};
PROCESS_INFORMATION processInfo;
if (CreateProcess(path, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
    WaitForSingleObject(processInfo.hProcess, INFINITE);
    CloseHandle(processInfo.hProcess);
    CloseHandle(processInfo.hThread);
}

这篇关于如何调用:: CreateProcess在c ++中以启动Windows可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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