1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <windows.h>
using namespace std;
int main(int argc, char *argv [])
{
//declaration for first process
PROCESS_INFORMATION pi;
STARTUPINFO info;
memset(&pi, 0, sizeof pi);
memset(&info, 0, sizeof info);
info.cb = sizeof STARTUPINFO;
info.dwFlags = STARTF_USESHOWWINDOW;
info.wShowWindow = SW_SHOWNORMAL;
//declaration for second process
PROCESS_INFORMATION pi2;
STARTUPINFO info2;
memset(&pi2, 0, sizeof pi2);
memset(&info2, 0, sizeof info2);
info2.cb = sizeof STARTUPINFO;
info.dwFlags = STARTF_USESHOWWINDOW;
info.wShowWindow = SW_SHOWNORMAL;
int choose;
char er; //exit or restart a program
replay:
cout << "Which program vish run - 1/2?" << endl;
cin >> choose;
if (choose==1)
{
CreateProcess(NULL, //run first program
"d:C:\Folder1\\Folder2\\program1.exe",
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&info,
&pi);
}
if (choose==2)
{
CreateProcess(NULL, //run second program
"d:C:\\Folder3\\Folder4\\program2",
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&info,
&pi);
}
else
{
while (1)
{
cout << "Wrong number!" << endl;
cout << "Waiting 5 seconds:" << endl;
for (int wrong=5; wrong > 0; wrong--)
{
cout << wrong;
Sleep (1000);
}
goto replay;
}
}
cout << "Press Q - quit program" << endl;
cin >> er;
if ((er=='Q')||(er=='q'))
{
for (int bay=5; bay > 0; bay--)
{
cout << bay;
Sleep (1000);
}
}
else
{
cout << "Error!!!" << endl;
Sleep (2000);
return -1;
}
return 0;
}
|