-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex1.cpp
More file actions
71 lines (64 loc) · 2.02 KB
/
ex1.cpp
File metadata and controls
71 lines (64 loc) · 2.02 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
BOOL CreateProcess(
LPCTSTR lpApplicationName, //文件名
LPTSTR lpCommandLine, //命令行
LPSECURITY_ATTRIBUTES lpProcessAttributes, //进程安全描述符
LPSECURITY_ATTRIBUTES lpThreadAttributes, //主线程安全描述符
BOOL bInheritHandles, //是否继承句柄
DWORD dwCreationFlags, //标识
LPVOID lpEnvironment, //环境变量指针
LPCTSTR lpCurrentDirectory, //当前目录
LPSTARTUPINFO lpStartupInfo, //启动信息结构
LPPROCESS_INFORMATION lpProcessInformation, //进程信息结构,pcb块
);
*/
#include <windows.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
using namespace std;
#define MAX_LINE_LEN 80
int main(int argc,char *argv[]) {
char cmdLine[MAX_LINE_LEN];
LPCTSTR lpApplicationName = NULL;
LPSECURITY_ATTRIBUTES processSA = NULL;
LPSECURITY_ATTRIBUTES threadSA = NULL;
BOOL shareRights = TRUE;
DWORD creationMask = CREATE_NEW_CONSOLE;
LPVOID environment = NULL;
LPTSTR curDir = NULL;
/* Result */
STARTUPINFO startInfo;
PROCESS_INFORMATION processInfo;
ZeroMemory(&startInfo,sizeof(startInfo));
startInfo.cb = sizeof(startInfo);
fstream lx("batch",ios::in);
while(lx.getline(cmdLine,100)){
// printf("%s",cmdLine);
if(!CreateProcess(
lpApplicationName, /* File name of executable */
cmdLine, /* Command line */
processSA, /* Process inherited security */
threadSA, /* Thread inherited security */
shareRights, /* Right propagation */
creationMask, /* Various creation flags */
environment, /* Environment variabkesr */
curDir, /* Child's current directory */
&startInfo,
&processInfo
)
)
{
fprintf(stderr,"CreatProcess failed on error %d\n",GetLastError());
ExitProcess(1);
};
fprintf(stdout,"The Child Process's PID: %d.\n", processInfo.dwProcessId);
fprintf(stdout,"The Parent Process finish.\n");
Sleep(500);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
};
Sleep(100000);
return 0;
}