zoukankan      html  css  js  c++  java
  • 创建进程API CreateProcess Demo

    #include <windows.h>
    #include
    "console.h"
    int main()
    {
    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    ZeroMemory(
    &si, sizeof(si));
    si.cb
    = sizeof(si);
    CHAR szSysPath[MAX_PATH];
    if (GetSystemDirectory(szSysPath,MAX_PATH)>0)//get windows system dir
    {
    strcat_s(szSysPath,MAX_PATH,
    "//notepad.exe");
    if(CreateProcess(szSysPath,"",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
    {
    WaitForSingleObject(pi.hThread,INFINITE);
    //wait until quit notepad.exe
    }
    }
    return 0;
    }

      

    如果指定CREATE_SUSPENDED:

    #include <windows.h>
    #include
    "console.h"
    int main()
    {
    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    ZeroMemory(
    &si, sizeof(si));
    si.cb
    = sizeof(si);
    CHAR szSysPath[MAX_PATH];
    if (GetSystemDirectory(szSysPath,MAX_PATH)>0)//get windows system dir
    {
    strcat_s(szSysPath,MAX_PATH,
    "//notepad.exe");
    if(CreateProcess(szSysPath,"",NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&si,&pi))
    {
    ResumeThread(pi.hThread);
    //if CREATE_SUSPENDED si specified call ResumeThread to start notepad.exe
    WaitForSingleObject(pi.hThread,INFINITE);//wait until quit notepad.exe
    }
    }
    return 0;
    }

      

      

  • 相关阅读:
    VirtualBox 使用技巧
    ThreadPoolExecutor 线程池任务队列分析 与 利特尔法则(Little's law)
    AQS 与 LockSupport
    Matrix
    Fire Net
    Travelling
    Cannon
    N皇后问题
    Safecracker
    #include <algorithm>中sort的一般用法
  • 原文地址:https://www.cnblogs.com/oyjj/p/2132858.html
Copyright © 2011-2022 走看看