On a Windows-10 machine, I am trying to run ssh.exe as a child process using createprocess, something like the below snippet:
// 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;
}
The CreateProcess API fails with error 2 (file not found) when child_cmd parameter contains “C:\\Windows\\System32\\OpenSSH\\ssh.exe”. What is puzzling is that, this file - ‘C:\Windows\System32\OpenSSH\ssh.exe’ - exists on the machine; yet, CreateProcess() reports error 2. If I copied ‘C:\Windows\System32\OpenSSH\ssh.exe’ [from command prompt] to some other location, say ‘C:\tmp\System32_OpenSSH\ssh.exe’ and then call CreateProcess() with child_cmd parameter containing “C:\\tmp\\System32_OpenSSH\\ssh.exe”, the exact same program works like a charm. Any clue what is going on here? Are there any OS imposed restrictions regarding C:\Windows\system32 folder?
I faced similar problem with file copy as well - system("copy C:\\Windows\\system32\\OpenSSH\\ssh.exe OpenSSH_ssh.exe").