Search code examples
c++pid

start on certain PID c++


I'am trying to start batch file on certain PID, or get PID what program started on. I really have no idea how to do that.

    system("start C:\\testing\\vw.bat");
    Sleep(2000); //1000 = 1s

After this code is executed I need to close "vw.bat", but not close other batch files that are running.


Solution

  • PROCESS_INFORMATION pi;
    STARTUPINFO si{};
    si.cb = sizeof(si);
    
    BOOL success = CreateProcess("start C:\\testing\\vw.bat", NULL, NULL, NULL, TRUE, 0, NULL, "C:\\testing\\", &si, &pi);
    if (success)
    {
        int pid = pi.dwProcessId;
    }