Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8094969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:58:01+00:00 2026-06-05T20:58:01+00:00

if I am using CreateProcess() multiple times, is okay to share the PROCESS_INFORMATION and

  • 0

if I am using CreateProcess() multiple times, is okay to share the PROCESS_INFORMATION and STARTUPINFO variables? Or is it really bad practice? I’ve read quite a bit of documentation, but I can’t find any examples about handling CreateProcess() calls more than once.

As an example, say I have the fake function below:

    int SampleClass::sampleFn1(){ 
        //Variables
        STARTUPINFOW siStartInfo; 
        PROCESS_INFORMATION piProcInfo; 
        memset(&siStartInfo, 0, sizeof(siStartInfo)); 
        memset(&piProcInfo, 0, sizeof(piProcInfo)); 
        siStartInfo.cb = sizeof(siStartInfo); 

        //let us assume cmdPath = cmd.exe directory, and cmdTxtPtr has correct text
        if(!CreateProcess(cmdPath, cmdTxtPtr, NULL, NULL, false, 0, 
        NULL, NULL, &siStartInfo, &piProcInfo)){
            return 1; //failed at step 1
        }
        if(!CreateProcess(cmdPath,_T("/C ant debug"),NULL,NULL,false,0,NULL,
        (LPCTSTR)directory,&siStartInfo,&piProcInfo)){
            return 2; //failed at debug
        }
        WaitForSingleObject(piProcInfo.hProcess,10000);
        result = GetExitCodeProcess(piProcInfo.hProcess,&exitCode);
        CloseHandle(piProcInfo.hProcess);
        CloseHandle(piProcInfo.hThread);
        return 0;//finished
    }

A similar function happens to work in my program, but I’d like to make it as safe as possible.

Or… Should I do something like the code below instead:

    int SampleClass::sampleFn2(){   
        //Variables
        STARTUPINFOW siStartInfo; 
        PROCESS_INFORMATION piProcInfo; 
        memset(&siStartInfo, 0, sizeof(siStartInfo)); 
        memset(&piProcInfo, 0, sizeof(piProcInfo)); 
        siStartInfo.cb = sizeof(siStartInfo); 

        //let us assume cmdPath = cmd.exe directory, and cmdTxtPtr has correct text
        if(!CreateProcess(cmdPath, cmdTxtPtr, NULL, NULL, false, 
        0, NULL, NULL, &siStartInfo, &piProcInfo)){
            return 1; //failed at update project
        }
        WaitForSingleObject(piProcInfo.hProcess,10000);
        result = GetExitCodeProcess(piProcInfo.hProcess,&exitCode);
        CloseHandle(piProcInfo.hProcess);
        CloseHandle(piProcInfo.hThread);

        memset(&siStartInfo, 0, sizeof(siStartInfo)); 
        memset(&piProcInfo, 0, sizeof(piProcInfo)); 
        siStartInfo.cb = sizeof(siStartInfo); 
        if(!CreateProcess(cmdPath,_T("/C ant debug"),NULL,NULL,
        false,0,NULL,(LPCTSTR)directory,&siStartInfo,&piProcInfo)){
            return 2; //failed at debug
        }
        WaitForSingleObject(piProcInfo.hProcess,10000);
        result = GetExitCodeProcess(piProcInfo.hProcess,&exitCode);
        CloseHandle(piProcInfo.hProcess);
        CloseHandle(piProcInfo.hThread);
        return 0;//finished
    }

Or do they both being handled poorly? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:58:03+00:00Added an answer on June 5, 2026 at 8:58 pm

    AFAIK the CreateProcess function writes into both the STARTUPINFO and PROCESSINFO structure, so unless you don’t care about any of that info, which I think you should, you could do the second example you give.

    By doing doing memset with 0, you reset all data in the structs to 0.

    I’m not sure that this is very good practice, but maybe someone else can give more insight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a process using CreateProcess() . This is the code: STARTUPINFO si
I am using CreateProcess function for creating the process, is there any option to
I'm executing an external application using the CreateProcess function, in order which such application
I'm spawning a process from Win32 using CreateProcess , setting the hStdOutput and hStdError
I'm using PyWin32's win32process.CreateProcess to start up a GUI program that has functionality I
My Windows XP/7 program launches a child process using the Windows API CreateProcess() function
I'm using CreateProcess() with startup flags set to STARTF_USESHOWWINDOW and SW_HIDE to start an
I am trying to start a server using CreateProcess(). Here is the Code: int
I am trying to create a program that calls another process using CreateProcess. After
I create a process using CreateProcess() with the CREATE_SUSPENDED and then go ahead to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.