-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubProcess.cpp
More file actions
49 lines (38 loc) · 1.01 KB
/
SubProcess.cpp
File metadata and controls
49 lines (38 loc) · 1.01 KB
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
#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
void subProcessTest()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
LPTSTR szCmdline = _tcsdup(TEXT("C:\\Windows\\Notepad.exe"));
try
{
BOOL temp = CreateProcess(NULL,
szCmdline,
NULL,
NULL, // don't inherit thread handle
FALSE, // disable handle inheritance
0, // no creation flags
NULL, // use parent's environment block
NULL, // use parent's existing directory
&si,
&pi);
{
fprintf(stderr, "Create Process Failed");
return;
}
}
catch(char e)
{
}
// parent will wait for the child to complete
WaitForSingleObject(pi.hProcess, INFINITE);
printf("Child Complete");
// close handles
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}