【发布时间】:2020-04-22 07:09:10
【问题描述】:
在 Windows-10 机器上,我尝试使用 createprocess 将 ssh.exe 作为子进程运行,类似于下面的 sn-p:
// Create the child process.
bSuccess = CreateProcess(NULL,
child_cmd, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
// If an error occurs, exit the application.
if (!bSuccess)
{
ErrorExit(TEXT("CreateProcess"));
return NULL;
}
当 child_cmd 参数包含“C:\\Windows\\System32\\OpenSSH\\ssh.exe”时,CreateProcess API 失败并出现错误 2(找不到文件)。令人费解的是,这个文件 - ‘C:\Windows\System32\OpenSSH\ssh.exe’ - 存在于机器上;然而,CreateProcess() 报告错误 2。如果我将 'C:\Windows\System32\OpenSSH\ssh.exe' [从命令提示符] 复制到其他位置,请说 'C:\tmp\System32_OpenSSH\ssh.exe' 和然后使用包含“C:\\tmp\\System32_OpenSSH\\ssh.exe”的 child_cmd 参数调用 CreateProcess(),完全相同的程序就像一个魅力。任何线索这里发生了什么?操作系统对 C:\Windows\system32 文件夹是否有任何限制?
我在文件复制方面也遇到了类似的问题 - system("copy C:\\Windows\\system32\\OpenSSH\\ssh.exe OpenSSH_ssh.exe")。
【问题讨论】:
-
Win32上的错误代码2是
"The system cannot find the file specified. "
标签: c windows createprocess system32