【发布时间】:2018-11-26 11:39:59
【问题描述】:
我编写了一个显示 Hello World 的 Project.exe。编写主进程,创建Project.exe的子进程。但是我把Projetc.exe放到C:/Windows/System32/上时,无法正确创建Project.exe的子进程,但是放到其他目录下可以正常创建。
主程序如下:
#include <Windows.h>
#include <string.h>
#include <stdio.h>
int main() {
STARTUPINFO si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
wchar_t *p = (wchar_t*)TEXT("C:/Windows/System32/Project1.exe");
CreateProcess(p, 0, 0, 0, 0, 0, 0, 0, &si, &pi);
DWORD CurId = GetCurrentProcessId(); //Get the ID of the current process
DWORD Pid = pi.dwProcessId; //ID of the created process
DWORD Tid = pi.dwThreadId; //The main thread ID of the created child process
printf("the ID of the current process: %d\nID of the created process: %d\nThe main thread ID of the created child process %d\n", CurId, Pid, Tid);
WaitForSingleObject(pi.hProcess, -1);
}
运算结果为:
如果我把Project.exe放在E:/下,结果是
这是什么原因,需要怎么改才能在/System32/下成功运行?
【问题讨论】: