Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <stdafx.h>
- #include "windows.h"
- #include "iostream"
- using namespace std;
- void OpenFilesAndFillProcessArray(int countOfFiles, HANDLE(&hProcessArray)[5]);
- void TerminateProcessArray(int countOfFiles, HANDLE(&hProcessArray)[5]);
- int main() {
- setlocale(LC_ALL, "Russian");
- int countOfFiles = 5;
- HANDLE hProcessArray[5] = {};
- OpenFilesAndFillProcessArray(countOfFiles, hProcessArray);
- if (hProcessArray[0]) {
- printf("\n");
- Sleep(4000);
- TerminateProcessArray(countOfFiles, hProcessArray);
- printf("\n");
- }
- system("pause");
- return 0;
- }
- void OpenFilesAndFillProcessArray(int countOfFiles, HANDLE(&hProcessArray)[5]) {
- STARTUPINFO sti;
- PROCESS_INFORMATION pri;
- LPCWSTR notepadPath = TEXT("C:\\Windows\\System32\\notepad.exe");
- ZeroMemory(&sti, sizeof(sti));
- sti.cb = sizeof(sti);
- ZeroMemory(&pri, sizeof(pri));
- for (int i = 0; i < countOfFiles; i++) {
- BOOL isCreatedFile = CreateProcess(
- notepadPath,
- NULL, NULL, NULL, FALSE, NULL, NULL, NULL,
- &sti, &pri
- );
- if (isCreatedFile) {
- cout << "Process " << pri.hProcess << " created\n";
- Sleep(1000);
- hProcessArray[i] = pri.hProcess;
- } else {
- printf("Invalid path to programm.\n");
- }
- }
- }
- void TerminateProcessArray(int countOfFiles, HANDLE(&hProcessArray)[5]) {
- for (int i = countOfFiles - 1; i >= 0; i--) {
- if (hProcessArray[i]) {
- cout << "Process " << hProcessArray[i] << " will be terminate\n";
- TerminateProcess(hProcessArray[i], NO_ERROR);
- Sleep(400);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment