MSSQLWIKI

Karthick P.K on SQL Server

How to Create process in c++….. CreateProcess function

Posted by Karthick P.K on December 31, 2011

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

void main()
{
    int N;    
    cout<<"Enter count for process:";
    cin>>N;

    PROCESS_INFORMATION *x;
    STARTUPINFO *startup_info;

    startup_info = new STARTUPINFO[N];
    x =new  PROCESS_INFORMATION[N]; 
    HANDLE *h;
    h = new HANDLE[N];
    for (int i=0;i<N;i++)
        {
            memset((char *)&startup_info[i], 0, sizeof(STARTUPINFO));
            startup_info[i].cb = sizeof(STARTUPINFO);
            startup_info[i].dwFlags = STARTF_USESTDHANDLES;
            startup_info[i].hStdInput = GetStdHandle(STD_INPUT_HANDLE);
            printf("\nProcess creation starting:%d",i);
            CreateProcess("c:\\windows\\notepad.exe",NULL,NULL,NULL,FALSE,0x00010000,NULL,NULL,startup_info,&x[i]);
            h[i]= x[i].hProcess;
        
        }
        
    WaitForMultipleObjects(N, h,TRUE,INFINITE);
    
    for (int i=0;i<N;i++)
        {
        CloseHandle(x[i].hProcess);
        CloseHandle(x[i].hThread);
        }

}
 
 
 
Thanks
Karthick P.K

2 Responses to “How to Create process in c++….. CreateProcess function”

  1. […] How to Create process in c++….. CreateProcess function […]

  2. kiospasti said

    Nice, thank you..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: