'How do you launch multiple executables (or files) at the same time using CreateProcess in C++?

I am trying to launch multiple batch files at the same time to make it easier for what I'm doing. I would like them to have separate command windows and have their own titles like "Server: Hub", "Server: Spleef", etc. I know Startupinfo can do that somehow, but I don't even know what code to put in for that. I got the CreateProcess code from here: https://stackoverflow.com/a/15440094/18369260.

Code:

#include <windows.h>
#include <string>
#include <iostream>
using namespace std;

VOID startup(LPCTSTR lpApplicationName)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    CreateProcess(lpApplicationName,
        NULL,
        NULL,
        NULL,
        FALSE,
        0,
        NULL,
        L"C:\\Users\\Anston Sorensen\\Desktop\\Minecraft Servers\\Minecraft Server\\",
        &si,
        &pi
    );
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
}

int main() {
    startup(L"C:\\Users\\Anston Sorensen\\Desktop\\Minecraft Servers\\Minecraft Server\\ServerStart512mb.bat");
    startup(L"C:\\Users\\Anston Sorensen\\Desktop\\Minecraft Servers\\Hub\\ServerStart512mb.bat");
    startup(L"C:\\Users\\Anston Sorensen\\Desktop\\Minecraft Servers\\Spleef\\ServerStart512mb.bat");
    startup(L"C:\\Users\\Anston Sorensen\\Desktop\\Minecraft Servers\\PVP\\ServerStart512mb.bat");
}

So far I only get the first file to launch.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source