I have this problem where I have to create a process and then when I am all done i must delete all processes that are created. I have tried to set up a linked list to do this but when i go to implement it it doesnt work>> I have all of my code up here for your use.
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <process.h>
struct Node
{
info p;
Node *next;
};
Node* head = NULL;
void addprocess(void)
{
Node* t;
t = new(node);
t->p = p1;
t->next = head;
head = t;
}
void closeprocess(void)
{
Node* t;
t = head;
while(t != NULL)
{
TerminateProcess(t->p.hprocess, 0);
t = t->next;
}
}
void menu (void)
{ int choice;
do
{
cout << " ---1. Calculator ---" << endl;
cout << " ---2. Notepad ---" << endl;
cout << " ---3. Paint ---"<< endl;
cout << " ---4. Terminate ---" << endl;
cin >> choice;
char lpApplicationName[100];
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProcessInfo;
ZeroMemory(&StartInfo, sizeof(StartInfo));
StartInfo.cb = sizeof(StartInfo);
if(choice == 1)
{
strcpy(lpApplicationName, "C:\\Windows\\system32\\calc.exe");
addprocess();
}
if(choice == 2)
{
strcpy(lpApplicationName, "C:\\Windows\\system32\\Notepad.exe");
addprocess();
}
if(choice == 3)
{
strcpy(lpApplicationName, "C:\\Windows\\system32\\mspaint.exe");
addprocess();
}
if (choice == 4)
{
closeprocess();
}
CreateProcess (lpApplicationName, NULL, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS|CREATE_NEW_CONSOLE, NULL, NULL, &StartInfo, &ProcessInfo);
}while(choice != 4);
}
void main(void)
{
menu();
}