Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Last active August 29, 2015 14:16
Show Gist options
  • Save arn-ob/c1f7ddf17ca426792653 to your computer and use it in GitHub Desktop.
Save arn-ob/c1f7ddf17ca426792653 to your computer and use it in GitHub Desktop.
Create a Child process ....... (Run only codeBlock GNU GCC compiler )
#include<stdio.h>
#include<Windows.h>
int main(VOID){
STARTUPINFO si;
PROCESS_INFORMATION pi;
// Allocate memory
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcess(NULL, "mspaint.exe", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
fprintf(stderr, "Create Process Failed");
return -1;
}
// parent will wait for the child to complete
WaitForSingleObject(pi.hProcess, INFINITE);
printf("Child Complete");
// Close Handles
CloseHandle(pi.hProcess);
CloseHandle(pi.hProcess);
}
Copy link

ghost commented Mar 10, 2015

include<stdio.h>

include<Windows.h>

int main(VOID){
STARTUPINFO si;
PROCESS_INFORMATION pi;
char szCmdline[] = "mspaint.exe";
// Allocate memory

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
//LPTSTR szCmdline = TEXT("C:\Windows\system32\mspaint.exe");
if (!CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
fprintf(stderr, "Create Process Failed");
return -1;
}

// parent will wait for the child to complete
WaitForSingleObject(pi.hProcess, INFINITE);
printf("Child Complete");

// Close Handles

CloseHandle(pi.hProcess);
CloseHandle(pi.hProcess);

return 0;
}

@ShawonAshraf
Copy link

Try allocating the memory manually. VC++ has some problems with memory allocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment