Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- int main()
- {
- STARTUPINFO startupInfo = { sizeof(startupInfo) };
- PROCESS_INFORMATION processInfo; // to save process information
- TCHAR CmdLine[] = TEXT("notepad"); // command line
- bool creationResult = CreateProcess(
- NULL, // use command line (no module name)
- CmdLine, // command line
- NULL, // process handle not inheritable
- NULL, // thread hanfle not inheritable
- FALSE, // handle inheritance = 0
- 0, // without creation flags
- NULL, // usint parent's environment block
- NULL, // using parent's start directory
- &startupInfo, // pointer to structure STARTUPINFO
- &processInfo // pointer to structure POINTER_INFORMATION
- );
- if (creationResult) // outputing some info about the process
- {
- std::cout << "process created\n PID\t" << processInfo.dwProcessId << "\n TID\t" << processInfo.dwThreadId << '\n';
- system("pause"); // than just wait for input, than attempt to terminate the process
- if (TerminateProcess(processInfo.hProcess, NO_ERROR)) std::cout << "process terminated\n"; // if process successfully terminated
- else std::cout << "error: process termination failed\n"; // it can fail in some cases, for example - when process already terminated by user
- }
- else std::cout << "error: process creation failed\n"; // idk if it can happen but for this case outputing error:
- }
- // Vologin V.A. KSU 2021
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement