转自:http://blog.csdn.net/zgl7903/article/details/5975284

转载这篇主要是记住:获得create的新进程运行结束时的返回值的方法

如下:

  1.  
    #include <malloc.h>
  2.  
     
  3.  
    DWORD run_Execute(LPCTSTR lpszFile, LPCTSTR lpszParam)
  4.  
    {
  5.  
    DWORD exitCode = 0;
  6.  
    PROCESS_INFORMATION pInfo = {0};
  7.  
    STARTUPINFO sInfo = {0};
  8.  
    sInfo.cb = sizeof(STARTUPINFO);
  9.  
    sInfo.wShowWindow = SW_SHOW;
  10.  
     
  11.  
    int nCmdLen = (_tcslen(lpszFile) + _tcslen(lpszParam) + 2) * sizeof(TCHAR);
  12.  
    LPTSTR lpszCmd = (LPTSTR)_alloca(nCmdLen);
  13.  
    memset(lpszCmd, 0, nCmdLen);
  14.  
    _tcscpy(lpszCmd, lpszFile);
  15.  
    if(lpszParam)
  16.  
    {
  17.  
    _tcscat(lpszCmd, _T(" "));
  18.  
    _tcscat(lpszCmd, lpszParam);
  19.  
    }
  20.  
     
  21.  
    if(CreateProcess(
  22.  
    NULL, //LPCTSTR lpApplicationName, // pointer to name of executable module
  23.  
    lpszCmd, //LPTSTR lpCommandLine, // pointer to command line string
  24.  
    NULL, //LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes
  25.  
    NULL, //LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes
  26.  
    FALSE, //BOOL bInheritHandles, // handle inheritance flag
  27.  
    0, //DWORD dwCreationFlags, // creation flags
  28.  
    NULL, //LPVOID lpEnvironment, // pointer to new environment block
  29.  
    NULL, //LPCTSTR lpCurrentDirectory, // pointer to current directory name
  30.  
    &sInfo, //LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
  31.  
    &pInfo)) //LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
  32.  
    {
  33.  
    // Wait until child process exits.
  34.  
    WaitForSingleObject( pInfo.hProcess, INFINITE );
  35.  
     
  36.  
    if (GetExitCodeProcess(pInfo.hProcess, &exitCode))
  37.  
    {
  38.  
    TRACE( _T("Exit code = %d/n"), exitCode);
  39.  
    }
  40.  
    else
  41.  
    {
  42.  
    TRACE( _T("GetExitCodeProcess() failed: %ld/n"), GetLastError());
  43.  
    ASSERT(0);
  44.  
    }
  45.  
     
  46.  
    // Close process and thread handles.
  47.  
    CloseHandle( pInfo.hProcess );
  48.  
    CloseHandle( pInfo.hThread );
  49.  
    }
  50.  
    else
  51.  
    {
  52.  
    TRACE( _T("CreateProcess() failed: %ld/n"), GetLastError());
  53.  
    ASSERT(0);
  54.  
    }
  55.  
     
  56.  
    return exitCode;
  57.  
    }

  1.  
    //测试示例
  2.  
    run_Execute(_T("notepad.exe"), _T("c://temp//aa.txt"));

jpg 转 rar 

使用CreateProcess创建新的process 并返回process运行结束返回值的更多相关文章

  1. Win32 API编程:使用CreateProcess创建新进程

    #include <windows.h> #include <tchar.h> #include <stdio.h> int main(int argc, char ...

  2. VC++ 使用CreateProcess创建新进程

    https://www.cnblogs.com/fancing/p/6477918.html #include <windows.h> #include <tchar.h> # ...

  3. android点击返回键,如何做到不destory当前activity,只是stop。重新返回该activity的 时候可以直接使用,不需要创建新的activity实例

    问题描述,如题目: android点击返回键,顺序执行 pause,stop,destory. 以至于想重新进入这个activity的时候还要重新执行onCreate()方法,那么如何解决不再重新执行 ...

  4. Delphi 使用CreateProcess创建进程并弹出进程PID值 (转)

    var  ExeName:PChar;  StartupInfo:TStartupInfo;  ProcessInfo:TProcessInformation;begin  FillChar(Proc ...

  5. linux进程学习-创建新进程

    init进程将系统启动后,init将成为此后所有进程的祖先,此后的进程都是直接或间接从init进程“复制”而来.完成该“复制”功能的函数有fork()和clone()等. 一个进程(父进程)调用for ...

  6. WebAPi之SelfHost自创建证书启动Https疑难解惑及无法正确返回结果

    前言 话说又来需求了,之前对于在SelfHost中需要嵌套页面并操作为非正常需求,这回来正常需求了,客户端现在加了https,老大过来说WebAPi访问不了了,这是什么情况,我去试了试,还真是这个情况 ...

  7. 用Kotlin开发Android应用(II):创建新项目

    这是关于Kotlin的第二篇.各位高手发现问题,请继续“拍砖”. 原文标题:Kotlin for Android(II): Create a new project 原文链接:http://anton ...

  8. Drupal8开发教程:模块开发——创建新页面

    之前我们已经通过<Drupal8开发教程:认识.info.yml文件>对模块的YAML文件有了了解,今天我们来看如何通过模块开发的方式添加一个新的页面. 在 Drupal 7 中,通过模块 ...

  9. (转)Qt Model/View 学习笔记 (四)——创建新的Models

    创建新的Models 介绍 model/view组件之间功能的分离,允许创建model利用现成的views.这也可以使用标准的功能 图形用户接口组件像QListView,QTableView和QTre ...

随机推荐

  1. SQL Server 定时执行SQL语句的方法

    SQL SERVER 定时任务,你可以启动一下.不过要想更加直观的控制,直接写一个程序,定时执行你的存储过程. 1.设置“SQL Server 代理”(SQL Server Agent)服务随系统启动 ...

  2. PLSQL Developer连接不上64位Oracle 10g的解决办法

    下载instantclient-basic-win32-10.2.0.4.zip 假设Oracle 10g的安装目录为D:\oracle\product\10.2.0\db1 首先,将instantc ...

  3. C# 窗体间传值(使用委托与自定义事件)

    using System; using System.Drawing; using System.Windows.Forms; namespace 跨窗体调用控件 { public partial c ...

  4. Windows7双系统卸载Ubuntu

    正确的删除ubuntu方法如下: 第1步,修复MBR 1.进入win7,下载个软件MbrFix.exe,放在C:\windows\system32文件夹中 2.点击开始>所有程序>附件&g ...

  5. 图像处理、计算机视觉与模式识别“SCI期刊和顶级会议”总结

    期刊: best (1) IEEE Transactions on Pattern Analysis and Machine Intelligence,IEEE模式分析与机器智能汇刊,简称PAMI,是 ...

  6. unity3d 读取usb摄像头

    using UnityEngine; using System.Collections; public class C : MonoBehaviour { private WebCamTexture ...

  7. [转]MBProgressHUD 源码分析

    源码来源: https://github.com/jdg/MBProgressHUD 版本:0.9.1 MBProgressHUD是一个显示HUD窗口的第三方类库,用于在执行一些后台任务时,在程序中显 ...

  8. Unity UGUI 的RectTransform参数的设置

    1.改变RectTransform的top GetComponent<RectTransform>().offsetMax = new Vector2(GetComponent<Re ...

  9. 将windbg设置为默认调试器命令

    前提条件:安装好windbg软件(默认安装位置) 以截取组态王运行系统崩溃为例: 64位系统0.文件更新替换 将Touchvew.exe以及Touchvew.pdb覆盖替换C:\Program Fil ...

  10. Bootstrap——导航居中

    这是采用了栅格,设置缩进,使看起来居中,但是手机浏览会靠到最左边.另外center-block类好像也不管用. <div class="row"> <ul cla ...