根据老师给的实验指导书做的
- # include
- # include
- # include
- int main()
- {
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory(&si, sizeof(si));
- si.cb = sizeof(si);
- ZeroMemory(&pi, sizeof(pi));
- TCHAR szCommandLine[] = TEXT("first");
- if (!CreateProcess(NULL,
- szCommandLine,
- NULL,
- NULL,
- FALSE,
- 0,
- NULL,
- NULL,
- &si,
- &pi))
- {
- fprintf(stderr, "Createprocess Failed \n\n\n");
- system("pause");
- exit(0);
- }
- int x;
- while (true)
- {
- printf("请输入要选择的操作:\n0: 销毁进程 \ n1: 挂起进程 \ n2: 激活进程 \ n3: 退出 \ n");
- scanf("%d",&x);
- switch (x)
- {
- case 0:
- if (TerminateProcess(pi.hProcess, 0))
- printf("进程销毁成功");
- break;
- case 1:
- if (SuspendThread(pi.hThread))
- printf("挂起进程成功");
- else
- printf("挂起失败");
- break;
- case 2:
- if (ResumeThread(pi.hThread))
- printf("激活进程成功");
- else
- printf("激活失败");
- break;
- case 3:
- exit(0);
- default:
- printf("选项不正确");
- }
- }
- return 0;
- }
如果把 szCommandLine 字符串的内容改成跟代码文件的名字相同, 会发生有意思的事情哦, 比如文件名 first.cpp 哈代码中 TCHAR szCommandLine[] = TEXT("first"); 这句, 很有意思的哦
来源: https://www.2cto.com/kf/201810/784230.html