Professional Documents
Culture Documents
BC 200203060
BC 200203060
BC 200203060
Question:
Write a program in C/C++ :
1. To create Parent Process and Child Process using the Windows
CreateProcess() API. Set the parameters as:
a. Set the path to the executable program written in C/C++ that the parent
process wants to run. The name of the C/C++ file should be the compiled
version “PrintText.exe” and it should be placed in the “Document”
folder of your desktop or laptop system. You have to put the code in
“PrintText.cpp” file to print your “Name” and “Roll Number” five
times, each time with a newline.
b. No command-line parameters are being passed to the child process.
c. Security attributes for the child process and thread should default
d. Handles for the child process and thread are not inheritable.
e. No creation flags are specified.
f. The child process uses the environment block of the parent process.
g. The child process uses the starting directory of the parent process.
h. A pointer to the STARTUPINFO structure
i. A pointer to the PROCESS_INFORMATION structure.
Note:
1. Include <iostream >, <windows.h>, and < tchar.h> header files in your
program.
2. Focus only what has been asked in the assignment. Marks will be deducted
on including extra or irrelevant code.
3. Question requires a complete program.
4. After the main code, you should place the code of “PrintText.cpp”. The
sample pattern of your assignment solution should be as:
Main code:
#include <iostream>
#include <windows.h>
#include <tchar.h>
int main() {
_TCHAR szPath[] = _T("C:\\Users\\Public\\Documents\\PrintText.exe");
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si); // Corrected typo: si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else {
std::cout << "Error Code: " << GetLastError() << std::endl;
}
return 0;
}//main code ended
PrintText code:
#include <iostream>
int main(){
for(int i = 0; i<5; i++){
std::cout <<"NAME: TALHA ABBAS<< std::endl;
std::cout <<"Roll Number: BC200203060" << std::endl;
}
} //End
5. Your solution should be a single Microsoft Word file (doc or docx). File in
any other format will be awarded zero marks.